Package share

Source Code of share.ServerUpdater

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);
      }

    });
  }

}
TOP

Related Classes of share.ServerUpdater

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.