/**
* This {@link BasicLibrary} will access a remote server to list the available
- * stories, and download the one you try to load to the local directory
+ * stories, and download the ones you try to load to the local directory
* specified in the configuration.
*
* @author niki
}
@Override
- protected int getNextId() {
+ public synchronized void delete(String luid) throws IOException {
throw new java.lang.InternalError(
"No write support allowed on remote Libraries");
}
@Override
- protected void doDelete(String luid) throws IOException {
+ public void setSourceCover(String source, String luid) {
throw new java.lang.InternalError(
"No write support allowed on remote Libraries");
}
+ // All the following methods are only used by Save and Delete in
+ // BasicLibrary:
+
@Override
- protected Story doSave(Story story, Progress pg) throws IOException {
- throw new java.lang.InternalError(
- "No write support allowed on remote Libraries");
+ protected int getNextId() {
+ throw new java.lang.InternalError("Should not have been called");
}
@Override
- public void setSourceCover(String source, String luid) {
- throw new java.lang.InternalError(
- "No write support allowed on remote Libraries");
+ protected void doDelete(String luid) throws IOException {
+ throw new java.lang.InternalError("Should not have been called");
+ }
+
+ @Override
+ protected Story doSave(Story story, Progress pg) throws IOException {
+ throw new java.lang.InternalError("Should not have been called");
}
}
import be.nikiroo.utils.serial.ConnectActionServer;
import be.nikiroo.utils.serial.Server;
+/**
+ * Create a new remote server that will listen for order on the given port.
+ * <p>
+ * The available commands are:
+ * <ul>
+ * <li>GET_METADATA *: will get the metadata of all the stories in the library</li>
+ * <li>GET_STORY [luid]: will return the given story if it exists (or NULL if
+ * not)</li>
+ * </ul>
+ *
+ * @author niki
+ */
public class RemoteLibraryServer extends Server {
+ /**
+ * Create a new remote server (will not be active until
+ * {@link RemoteLibraryServer#start()} is called).
+ *
+ * @param port
+ * the port to listen on
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
public RemoteLibraryServer(int port) throws IOException {
- super(Version.getCurrentVersion(), port, true);
+ super(port, true);
}
@Override
System.out.println(String.format("COMMAND: [%s], ARGS: [%s]", command,
args));
- if (command != null) {
- if (command.equals("GET_METADATA")) {
- if (args != null && args.equals("*")) {
- List<MetaData> metas = Instance.getLibrary().getMetas(null);
- return metas.toArray(new MetaData[] {});
- }
- } else if (command.equals("GET_STORY")) {
- if (args != null) {
- return Instance.getLibrary().getStory(args, null);
- }
+ // TODO: progress (+send name + %age info back to client)
+
+ if ("GET_METADATA".equals(command)) {
+ if (args != null && args.equals("*")) {
+ List<MetaData> metas = Instance.getLibrary().getMetas(null);
+ return metas.toArray(new MetaData[] {});
+ }
+ } else if ("GET_STORY".equals(command)) {
+ if (args != null) {
+ return Instance.getLibrary().getStory(args, null);
}
}