Package chat.connection

Source Code of chat.connection.AbstractChatConnection

package chat.connection;


import handlers.AbstractContextualHandler;
import handlers.sets.PrivateChatHandlerSet;

import java.io.IOException;
import java.io.ObjectOutputStream;

import chat.PrivateChatSession;

import common.connection.AbstractCommunicationSet;
import common.connection.ConnectionWriterInterface;
import common.handlers.AbstractHandlerSet;

import main.PeerProtocol;
import main.settings.Settings;

import connection.peer.GenericPeerConnection;


public abstract class AbstractChatConnection extends GenericPeerConnection
{
  private static final PrivateChatHandlerSet HANDLER_SET = new PrivateChatHandlerSet();

  protected PrivateChatSession session;

  protected AbstractChatConnection(AbstractCommunicationSet source) throws IOException
  {
    super(source);
  }

  public void initializeConnection()
  {
    session = new PrivateChatSession(this);
  }

  public void finalizeConnection()
  {
    session.notifyTerminated();
  }

  protected AbstractHandlerSet getHandlerSet()
  {
    return HANDLER_SET;
  }

  public AbstractContextualHandler getContextualHandler(int protocolId, int opcode)
      throws IOException, ClassNotFoundException
  {
    return PrivateChatHandlerSet.HANDLERS[protocolId][opcode].createContext(session,
        is);
  }

  public void sendNickname()
  {
    int protocolId = PeerProtocol.PROTOCOL_CHAT;
    int opcode = PeerProtocol.Chat.OP_NICKNAME;
    sendOverlapped(protocolId, opcode, new ConnectionWriterInterface()
    {
      public void run(ObjectOutputStream os) throws IOException
      {
        os.writeUTF(Settings.application.nickname);
      }

    });
  }

}
TOP

Related Classes of chat.connection.AbstractChatConnection

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.