Package handlers.files

Source Code of handlers.files.KeywordsHandler

package handlers.files;


import iteration.ConnectionIterationClientInterface;
import iteration.context.IterationContextInterface;
import iteration.context.KeywordsContext;

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

import static main.ServerMain.*;

import connection.ClientConnection;
import handlers.AbstractServerHandler;


public class KeywordsHandler extends AbstractServerHandler implements
    ConnectionIterationClientInterface
{
  private ClientConnection requestingClient;

  @SuppressWarnings("unchecked")
  public void execute(ClientConnection connection, ObjectInputStream is,
      ObjectOutputStream os) throws IOException, ClassNotFoundException
  {
    requestingClient = connection;

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

    int queryId = connection.addQuery(cookie, keywords);
    getConnectionManager().iterate(this, new KeywordsContext(queryId, keywords));
  }

  public void iterate(ClientConnection currentClient, IterationContextInterface context)
  {
    if (currentClient != requestingClient)
    {
      KeywordsContext customContext = context.queryKeywordsContext();
      currentClient.sendKeywords(customContext.getCookie(), customContext
          .getKeywords());
    }
  }

}
TOP

Related Classes of handlers.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.