Package net.yura.lobby.model

Examples of net.yura.lobby.model.Message


       if (writeThread==null) {
            writeThread = new Thread() {
                public void run() {
                    try {
                        while ( !Thread.interrupted() ) {
                            Message message;
                            synchronized (sendQueue) {
                                while (sendQueue.isEmpty()) {
                                    sendQueue.wait();
                                }
                                message = (Message)sendQueue.remove(0);
                            }

                            try {
//                                int size = access.computeAnonymousObjectSize(message);
//                                ByteArrayOutputStream bytes = new ByteArrayOutputStream(size);
//                                access.save(bytes, message);
//                                client.sendToNetwork(bytes.toByteArray());

                                TcpClient cl = client;
                                if (cl!=null) {
                                    int size = access.computeAnonymousObjectSize(message);
                                    ByteArrayOutputStream bytes = new ByteArrayOutputStream(size+4);
                                    new DataOutputStream(bytes).writeInt(size);
                                    access.save(bytes, message);
                                    cl.send( ByteBuffer.wrap( bytes.toByteArray() ) );
                                }
                            }
                            catch (InterruptedException in) {
                                throw in; // do not want to catch this
                            }
                            catch (Exception ex) {
                                Level level = (ex instanceof IOException && "not connected".equals(ex.getMessage())) ||
                                          (ex instanceof SocketException && "Broken pipe".equals(ex.getMessage())) ||
                                          (ex instanceof SocketException && "sendto failed: EPIPE (Broken pipe)".equals(ex.getMessage()))
                                        ?Level.INFO:Level.WARNING;
                                logger.log(level,"could not send "+message,ex);
                            }
                        }
                    }
                    catch (InterruptedException ex) { }
                }
            };
            writeThread.start();
       }
      
       System.out.println("sending message "+command+" "+param);
      
       Message message = new Message();
       message.setCommand(command);
       message.setParam(param);

       if (wait!=0) {
            message.setWait(new Integer(wait));
       }
      
       synchronized (sendQueue) {
            sendQueue.add(message);
            sendQueue.notify();
View Full Code Here


                while (true) {
                    if (size==-1 && data.available() >= 4) {
                        size = data.readInt();
                    }
                    else if (size>=0 && data.available() >= size) {
                        Message message = (Message)access.load(data, size);
                        size = -1;
                        messageFromServer(message);
                    }
                    else {
                        break;
View Full Code Here

        while (true) {
            if (cd.size==-1 && cd.data.available() >= 4) {
                cd.size = cd.data.readInt();
            }
            else if (cd.size>=0 && cd.data.available() >= cd.size) {
                Message message = server.decode(cd.data, cd.size);
                cd.size = -1;
                handleMessage(ch, message);
            }
            else {
                break;
View Full Code Here

    public GameType getGameType(int gameTypeId) {
        return classLoaders.get( gameTypeId );
    }

    public void send(LobbySession session, String command, Object param) {
        Message message = new Message();
        message.setCommand(command);
        message.setParam(param);
        LobbyServer.logger.info("Sending "+session+" "+message);
        server.send(session, message);
    }
View Full Code Here

TOP

Related Classes of net.yura.lobby.model.Message

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.