Package handlers.server.files

Source Code of handlers.server.files.KeywordsHandler

package handlers.server.files;


import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Collection;

import common.ClientServerProtocol;
import common.connection.ConnectionWriterInterface;

import connection.server.ServerConnection;
import handlers.AbstractContextualHandler;
import handlers.server.AbstractClientServerHandler;

import static main.ClientMain.*;


public class KeywordsHandler extends AbstractClientServerHandler
{
  private int cookie;
  private Collection<String> keywords;

  @SuppressWarnings("unchecked")
  private KeywordsHandler(ServerConnection connection, ObjectInputStream is)
      throws IOException, ClassNotFoundException
  {
    super(connection);

    cookie = is.readInt();
    keywords = (Collection<String>) is.readObject();
  }

  public KeywordsHandler()
  {
  }

  public AbstractContextualHandler createContext(ServerConnection connection,
      ObjectInputStream is) throws IOException, ClassNotFoundException
  {
    return new KeywordsHandler(connection, is);
  }

  protected void execute() throws IOException
  {
    final Object results = getSharedFilesTable().query(keywords);

    int protocolId = ClientServerProtocol.PROTOCOL_FILES;
    int opcode = ClientServerProtocol.Files.OP_RESULTS;
    connection.send(protocolId, opcode, new ConnectionWriterInterface()
    {
      public void run(ObjectOutputStream os) throws IOException
      {
        os.writeInt(cookie);
        os.writeObject(results);
      }

    });
  }

}
TOP

Related Classes of handlers.server.files.KeywordsHandler

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.