Package org.menacheri.jetserver.app

Examples of org.menacheri.jetserver.app.Session


    }
  }

  protected void onNetworkMessage(NetworkEvent event)
  {
    Session session = getSession();
    if (!session.isWriteable())
      return;
    DeliveryGuaranty guaranty = event.getDeliveryGuaranty();
    if (guaranty.getGuaranty() == FAST.getGuaranty())
    {
      Fast udpSender = session.getUdpSender();
      if (null != udpSender)
      {
        udpSender.sendMessage(event);
      }
      else
      {
        LOG.trace(
            "Going to discard event: {} since udpSender is null in session: {}",
            event, session);
      }
    }
    else
    {
      session.getTcpSender().sendMessage(event);
    }
  }
View Full Code Here


    getSession().getTcpSender().sendMessage(event);
  }
 
  protected void onConnect(ConnectEvent event)
  {
    Session session = getSession();
    if (null != event.getTcpSender())
    {
      session.setTcpSender(event.getTcpSender());
      // Now send the start event to session
      session.onEvent(Events.event(null, Events.START));
    }
    else
    {
      if(null == getSession().getTcpSender())
      {
        logNullTcpConnection(event);
      }
      else
      {
        session.setUDPEnabled(true);
        session.setUdpSender(event.getUdpSender());
      }
    }
  }
View Full Code Here

    }
  }
 
  protected void onReconnect(ConnectEvent event)
  {
    Session session = getSession();
    // To synchronize with task for closing session in ReconnectRegistry service.
    synchronized(session){
      @SuppressWarnings("unchecked")
      SessionRegistryService<String> reconnectRegistry = ((SessionRegistryService<String>) session
          .getAttribute(JetConfig.RECONNECT_REGISTRY));
      if (null != reconnectRegistry && Session.Status.CLOSED != session.getStatus())
      {
        reconnectRegistry.removeSession((String) session
            .getAttribute(JetConfig.RECONNECT_KEY));
      }
    }
    onConnect(event);
  }
View Full Code Here

  }

  @SuppressWarnings("unchecked")
  protected void onException(Event event)
  {
    Session session = getSession();
    session.setStatus(Session.Status.NOT_CONNECTED);
    session.setWriteable(false);
    session.setUDPEnabled(false);// will be set to true by udpupstream handler on connect event.
    String reconnectKey = (String) session
        .getAttribute(JetConfig.RECONNECT_KEY);
    SessionRegistryService<String> registry = (SessionRegistryService<String>)session.getAttribute(JetConfig.RECONNECT_REGISTRY);
    if (null != reconnectKey && null != registry)
    {
      // If session is already in registry then do not re-register.
      if(null == registry.getSession(reconnectKey)){
        registry.putSession(
View Full Code Here

    }

    @Override
    public void run()
    {
      Session session = sessions.get(reconnectKey);
      if (null != session)
      {
        synchronized (session)
        {
          // at this point it could have been removed by re-connect
          // handler already, hence another null check required.
          Session removeSession = sessions.remove(reconnectKey);
          if (null != removeSession)
            removeSession.close();
        }
      }
    }
View Full Code Here

    GameRoomSessionBuilder sessionBuilder = new GameRoomSessionBuilder();
    sessionBuilder.parentGame(game).gameRoomName("Zombie_ROOM_1")
        .protocol(dummyProtocol);
    CountDownLatch latch = new CountDownLatch(1);
    AtomicLong counter = new AtomicLong(1l);
    Session gameRoomSession = new TestGameRoom(sessionBuilder, counter,
        latch);
    GameRoom gameRoom = (GameRoom) gameRoomSession;
    PlayerSession playerSession = gameRoom.createPlayerSession(null);
    gameRoom.connectSession(playerSession);
    playerSession.addHandler(new SessionHandlerLatchCounter(playerSession,
        counter, latch));

    // start test
    gameRoom.disconnectSession(playerSession);
    JetlangEventDispatcher gameDispatcher = (JetlangEventDispatcher) gameRoomSession
        .getEventDispatcher();
    assertNoListeners(gameDispatcher);
    Event event = Events.event(null, Events.SESSION_MESSAGE);
    playerSession.onEvent(event);
    assertFalse(latch.await(500, TimeUnit.MILLISECONDS));

    // Connect to another game room
    sessionBuilder.gameRoomName("Zombie_ROOM_2");

    Session gameRoomSession2 = new TestGameRoom(sessionBuilder, counter,
        latch);
    GameRoom gameRoom2 = (GameRoom) gameRoomSession2;
    gameRoom2.connectSession(playerSession);
    playerSession.addHandler(new SessionHandlerLatchCounter(playerSession,
        counter, latch));
View Full Code Here

    sessionBuilder.parentGame(game).gameRoomName("Zombie_ROOM_1")
        .protocol(dummyProtocol);
    CountDownLatch latch1 = new CountDownLatch(2);
    CountDownLatch latch2 = new CountDownLatch(2);
    AtomicLong counter = new AtomicLong(0l);
    Session gameRoomSession = new TestGameRoom(sessionBuilder, counter,
        latch1);
    GameRoom gameRoom = (GameRoom) gameRoomSession;
    PlayerSession playerSession = gameRoom.createPlayerSession(null);
    PlayerSession playerSession2 = gameRoom.createPlayerSession(null);
    PlayerSession playerSession3 = gameRoom.createPlayerSession(null);
View Full Code Here

    for (int i = 1; i <= NUM_OF_GAME_ROOMS; i++)
    {
      GameRoomSessionBuilder sessionBuilder = new GameRoomSessionBuilder();
      sessionBuilder.parentGame(game).gameRoomName("Zombie_ROOM_" + i)
          .protocol(DUMMY_PROTOCOL).eventDispatcher(new ExecutorEventDispatcher());
      Session gameRoomSession = new TestGameRoom(sessionBuilder);
      gameRoomSession.addHandler(new GameRoomSessionHandler(
          gameRoomSession));
      gameRoomList.add((GameRoom) gameRoomSession);
    }
    for (GameRoom gameRoom : gameRoomList)
    {
View Full Code Here

  public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
      throws Exception
  {
    // Get the session using the remoteAddress.
    SocketAddress remoteAddress = e.getRemoteAddress();
    Session session = udpSessionRegistry.getSession(remoteAddress);
    if(null != session)
    {
      Event event = (Event) e.getMessage();
      // If the session's UDP has not been connected yet then send a
      // CONNECT event.
      if (!session.isUDPEnabled())
      {
        event = getUDPConnectEvent(event, remoteAddress,
            (DatagramChannel) e.getChannel());
        // Pass the connect event on to the session
        session.onEvent(event);
      }
      else if (event.getType() == Events.CONNECT)
      {
        // Duplicate connect just discard.
        LOG.trace("Duplicate CONNECT {} received in UDP channel, "
            + "for session: {} going to discard", event, session);
      }
      else
      {
        // Pass the original event on to the session
        session.onEvent(event);
      }
    }
    else
    {
      LOG.trace("Packet received from unknown source address: {}, going to discard",remoteAddress);
View Full Code Here

    for (int i = 1; i <= NUM_OF_GAME_ROOMS; i++)
    {
      GameRoomSessionBuilder sessionBuilder = new GameRoomSessionBuilder();
      sessionBuilder.parentGame(game).gameRoomName("Zombie_ROOM_" + i)
          .protocol(DUMMY_PROTOCOL);
      Session gameRoomSession = new TestGameRoom(sessionBuilder);
      gameRoomSession.addHandler(new GameRoomSessionHandler(
          gameRoomSession));
      gameRoomList.add((GameRoom) gameRoomSession);
    }
    for (GameRoom gameRoom : gameRoomList)
    {
View Full Code Here

TOP

Related Classes of org.menacheri.jetserver.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.