package share;
import java.io.IOException;
import java.io.ObjectOutputStream;
import common.ClientServerProtocol;
import common.connection.ConnectionWriterInterface;
import common.files.MultiNamedFile;
import common.files.SerializableFile;
import connection.server.ServerConnection;
public class ServerUpdater implements SharedFilesListenerInterface
{
private ServerConnection connection;
public ServerUpdater(ServerConnection connection)
{
this.connection = connection;
}
public void onAdd(MultiNamedFile file)
{
sendFiles(file);
}
private void sendFiles(final MultiNamedFile file)
{
int protocolId = ClientServerProtocol.PROTOCOL_FILES;
int opcode = ClientServerProtocol.Files.OP_ADD_FILE;
connection.sendOverlapped(protocolId, opcode, new ConnectionWriterInterface()
{
public void run(ObjectOutputStream os) throws IOException
{
os.writeObject(file);
}
});
}
public void onRemove(final SerializableFile file)
{
int protocolId = ClientServerProtocol.PROTOCOL_FILES;
int opcode = ClientServerProtocol.Files.OP_DEL_FILE;
connection.sendOverlapped(protocolId, opcode, new ConnectionWriterInterface()
{
public void run(ObjectOutputStream os) throws IOException
{
os.writeObject(file);
}
});
}
}