org.bdware.doip.cluster.InMemoryIrpClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of doip-audit-tool Show documentation
Show all versions of doip-audit-tool Show documentation
doip audit tool developed by bdware
The newest version!
package org.bdware.doip.cluster;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.bdware.irp.client.IrpClient;
import org.bdware.irp.exception.IrpClientException;
import org.bdware.irp.irplib.core.IrpMessageSigner;
import org.bdware.irp.irplib.exception.IrpConnectException;
import org.bdware.irp.stateinfo.StateInfoBase;
import java.io.Reader;
import java.util.List;
public class InMemoryIrpClient implements IrpClient {
JsonObject db;
public InMemoryIrpClient(JsonObject db) {
this.db = db;
}
public InMemoryIrpClient(Reader reader) {
db = JsonParser.parseReader(reader).getAsJsonObject();
}
@Override
public StateInfoBase resolve(String handle) throws IrpClientException {
if (db.has(handle)) {
StateInfoBase base = new StateInfoBase();
base.identifier = handle;
base.handleValues = db.get(handle).getAsJsonObject();
return base;
}
return null;
}
@Override
public String register(StateInfoBase hr) throws IrpClientException {
if (hr.identifier != null && hr.handleValues != null) {
db.add(hr.identifier, hr.handleValues);
return hr.identifier;
}
return null;
}
@Override
public String reRegister(StateInfoBase hr) throws IrpClientException {
if (hr.identifier != null && hr.handleValues != null) {
db.add(hr.identifier, hr.handleValues);
return hr.identifier;
}
return null;
}
@Override
public String unRegister(String handle) throws IrpClientException {
if (handle != null) db.remove(handle);
return handle;
}
@Override
public List batchRegister(StateInfoBase hr, int count) throws IrpClientException {
return null;
}
@Override
public void close() {
}
@Override
public void connect(String url) {
}
@Override
public void connect(String clientID, String LHSUrl, IrpMessageSigner signer) {
}
@Override
public void reconnect() throws IrpConnectException {
}
@Override
public boolean isConnected() {
return true;
}
}