Package org.menacheri.jetclient.app

Examples of org.menacheri.jetclient.app.Session


        .jetserverUdpHostName("255.255.255.255").udpPort(18090);
    LoginHelper loginHelper = builder.build();
    SessionFactory sessionFactory = new SessionFactory(loginHelper);
    ScheduledExecutorService taskExecutor = Executors.newSingleThreadScheduledExecutor();
    for(int i = 1; i<=50; i++){
      Session session = sessionFactory.createAndConnectSession();
      addDefaultHandlerToSession(session);
      GamePlay task = null;
      if((i % 2) == 0){
        task = new GamePlay(IAM.DEFENDER, session);
      }
View Full Code Here


        .jetserverUdpHostName("255.255.255.255").udpPort(18090);
    LoginHelper loginHelper = builder.build();
    SessionFactory sessionFactory = new SessionFactory(loginHelper);
    ScheduledExecutorService taskExecutor = Executors.newSingleThreadScheduledExecutor();
    for(int i = 1; i<=50; i++){
      Session session = sessionFactory.createAndConnectSession(getDefaultHandler());
      // Set the reconnect policy for reconnection.
      session.setReconnectPolicy(new ReconnectPolicy.ReconnectNTimes(2, 2000, loginHelper));
      GamePlay task = null;
      if((i % 2) == 0){
        task = new GamePlay(IAM.DEFENDER, session);
      }
      else{
View Full Code Here

   * @throws Exception
   */
  public Session createAndConnectSession() throws InterruptedException,
      Exception
  {
    Session session = createSession();
    connectSession(session);
    return session;
  }
View Full Code Here

  public abstract void onDataIn(Event event);

  public void onNetworkMessage(NetworkEvent networkEvent)
  {
    Session session = getSession();
    boolean writeable = session.isWriteable();
    MessageSender messageSender = null;
    if (networkEvent.getDeliveryGuaranty().getGuaranty() == DeliveryGuarantyOptions.FAST
        .getGuaranty())
    {
      messageSender = session.getUdpMessageSender();
    }
    else
    {
      messageSender = session.getTcpMessageSender();
    }
    if (writeable && null != networkEvent)
    {
      messageSender.sendMessage(networkEvent);
    }
View Full Code Here

  }

  public synchronized void onException(Event event)
  {
    Session session = getSession();
    String reconnectKey = (String) session
        .getAttribute(Config.RECONNECT_KEY);
    if (null != reconnectKey)
    {
      if(isReconnecting){
        return;
      }else{
        isReconnecting = true;
      }
      session.setWriteable(false);
      if (null != session.getReconnectPolicy())
      {
        session.getReconnectPolicy().applyPolicy(session);
      }
      else
      {
        System.err.println("Received exception event in session. "
            + "Going to close session");
View Full Code Here

   * @throws Exception
   */
  public Session createAndConnectSession(EventHandler... eventHandlers)
      throws InterruptedException, Exception
  {
    Session session = createSession();
    connectSession(session, eventHandlers);
    return session;
  }
View Full Code Here

  }

  @Override
  public void close()
  {
    Session session = NettyUDPClient.CLIENTS.remove(channel
        .getLocalAddress());
    if (null == session)
    {
      System.err.println("Possible memory leak occurred. "
          + "The session associated with udp localaddress: "
View Full Code Here

  public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
      throws Exception
  {
    // Lookup the session from the local address.
    DatagramChannel datagramChannel = (DatagramChannel) e.getChannel();
    Session session = NettyUDPClient.CLIENTS.get(datagramChannel
        .getLocalAddress());
    if (null != session)
    {
      Event event = (Event) e.getMessage();
      // Pass the event on to the session
      session.onEvent(event);
    }
  }
View Full Code Here

  public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
      throws Exception
  {
    System.err.println(e.getCause());
    DatagramChannel datagramChannel = (DatagramChannel) e.getChannel();
    Session session = NettyUDPClient.CLIENTS.get(datagramChannel
        .getLocalAddress());
    if (null != session)
    {
      Event event = Events.event(e, Events.EXCEPTION);
      session.onEvent(event);
    }
  }
View Full Code Here

  @Override
  public void channelDisconnected(ChannelHandlerContext ctx,
      ChannelStateEvent e) throws Exception
  {
    DatagramChannel datagramChannel = (DatagramChannel) e.getChannel();
    Session session = NettyUDPClient.CLIENTS.get(datagramChannel
        .getLocalAddress());
    if ((null != session) && !session.isShuttingDown())
    {
      Event event = Events.event(e, Events.DISCONNECT);
      session.onEvent(event);
    }
    else if (null != session)
    {
      System.out.println("Session is already shutting down. "
          + "Disconnect event will be discarded for channel {}"
View Full Code Here

TOP

Related Classes of org.menacheri.jetclient.app.Session

Copyright © 2018 www.massapicom. 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.