import be.nikiroo.fanfix.data.Story;
import be.nikiroo.utils.Progress;
import be.nikiroo.utils.Version;
-import be.nikiroo.utils.serial.ConnectActionClient;
+import be.nikiroo.utils.serial.server.ConnectActionClientObject;
/**
* This {@link BasicLibrary} will access a remote server to list the available
public class RemoteLibrary extends BasicLibrary {
private String host;
private int port;
+ private final String key;
/**
* Create a {@link RemoteLibrary} linked to the given server.
*
+ * @param key
+ * the key that will allow us to exchange information with the
+ * server
* @param host
* the host to contact or NULL for localhost
* @param port
* the port to contact it on
*/
- public RemoteLibrary(String host, int port) {
+ public RemoteLibrary(String key, String host, int port) {
+ this.key = key;
this.host = host;
this.port = port;
}
// TODO: progress
final List<MetaData> metas = new ArrayList<MetaData>();
MetaData[] fromNetwork = this.<MetaData[]> getRemoteObject( //
- new Object[] { "GET_METADATA", "*" });
+ new Object[] { key, "GET_METADATA", "*" });
if (fromNetwork != null) {
for (MetaData meta : fromNetwork) {
@Override
public BufferedImage getCover(final String luid) {
return this.<BufferedImage> getRemoteObject( //
- new Object[] { "GET_COVER", luid });
+ new Object[] { key, "GET_COVER", luid });
}
@Override
public BufferedImage getSourceCover(final String source) {
return this.<BufferedImage> getRemoteObject( //
- new Object[] { "GET_SOURCE_COVER", source });
+ new Object[] { key, "GET_SOURCE_COVER", source });
}
@Override
public synchronized Story getStory(final String luid, Progress pg) {
- return this.<Story> getRemoteObject(new Object[] { "GET_STORY", luid });
+ return this.<Story> getRemoteObject( //
+ new Object[] { key, "GET_STORY", luid });
}
@Override
@Override
public synchronized Story save(Story story, String luid, Progress pg)
throws IOException {
- getRemoteObject(new Object[] { "SAVE_STORY", story, luid });
+ getRemoteObject(new Object[] { key, "SAVE_STORY", story, luid });
// because the meta changed:
clearCache();
@Override
public synchronized void delete(String luid) throws IOException {
- getRemoteObject(new Object[] { "DELETE_STORY", luid });
+ getRemoteObject(new Object[] { key, "DELETE_STORY", luid });
}
@Override
public void setSourceCover(String source, String luid) {
this.<BufferedImage> getRemoteObject( //
- new Object[] { "SET_SOURCE_COVER", source, luid });
+ new Object[] { key, "SET_SOURCE_COVER", source, luid });
}
@Override
private <T> T getRemoteObject(final Object[] command) {
final Object[] result = new Object[1];
try {
- new ConnectActionClient(host, port, true) {
+ new ConnectActionClientObject(host, port, true) {
@Override
public void action(Version serverVersion) throws Exception {
try {
Object rep = send(command);
result[0] = rep;
} catch (Exception e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
}
}.connect();
} catch (IOException e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
}
try {
return (T) result[0];
} catch (Exception e) {
- Instance.syserr(e);
+ Instance.getTraceHandler().error(e);
return null;
}
}