Command Factories
Definition
In addition to commands the server allows the client to create session commands that can be invoked only by the creating client session. This is accomplished using factory commands. The factory commands are similar to static commands except that when a method of a factory command returns an object the server returns to the client an object proxy rather than the copy of the data as for static commands. Session commands may encapsulate client data and are garbage collected when the client proxy is garbage collected. The client may explicitly remove a session command casting the proxy to ISessionCommand interface and invoking remove().

Session Command Interfaces
In our application we need two types of dynamic commands. One command is for uploading a message to the server in smaller packets and another for downloading the message from the server. Let's suppose the message published or retrieved would be 100k characters. If we would call the publish() or request() methods in the synchronizer command then the transmission would be highly unparallel and would consume a lot of memory on both the client and server side as transmission buffers would have to be allocated to store the large message.

As for the static commands the session commands can only be invoked through the implemented interfaces:

public interface IUploader
{
    // sends the next packet in sequence and the last packet flag
    public void publish( String packet, boolean isLast ) throws IOException;
}

public interface IDownloader
{
    // requests the next packet in sequence
    // the client must check the last message flag returned in the response
    public IMessagePacket requestPacket() throws IOException;
}
Factory Interfaces
The factory command that returns these session commands implements the factory interfaces:
public interface IUploaderFactory
{
    public IUploader createUploader() throws IOException;
}

public interface IDownloaderFactory
{
    public IDownloader createDownloader() throws IOException;
}
See the server source code for the implementation of the Uploader, Downloader and the factory command.

Factory Declaration
The factory must be declared in the application.properties file specifying the factory flag:
Application.command=loader_factory
Application.command.loader_factory=com.accendia.datasynch.server.SynchronizerFactory
Application.command.loader_factory.enabled=true
Application.command.loader_factory.factory=true
The client must obtain a reference to the command factory proxy and invoke the proxy to create session commands:
...
uploaderFactory_ = (IUploaderFactory)serverContext_.getFactoryProxy(
                                                 applicationName, "loader_factory" );
...
IUploader uploader = uploaderFactory_.createUploader();
...