Package com.sun.sgs.impl.sharedutil

Examples of com.sun.sgs.impl.sharedutil.MessageBuffer


                    "The returned PasswordAuthentication must not be null");
            }

            String user = authentication.getUserName();
            String pass = new String(authentication.getPassword());
            MessageBuffer msg =
                new MessageBuffer(2 +
                    MessageBuffer.getSize(user) +
                    MessageBuffer.getSize(pass));
            msg.putByte(SimpleSgsProtocol.LOGIN_REQUEST).
                putByte(SimpleSgsProtocol.VERSION).
                putString(user).
                putString(pass);
            try {
                sendRaw(ByteBuffer.wrap(msg.getBuffer()).asReadOnlyBuffer());
            } catch (IOException e) {
                logger.logThrow(Level.FINE, e, "During login request:");
                logout(true);
            }
        }
View Full Code Here


                clientConnection = null;
                connectionStateChanging = false;
            }
            String reason = null;
            if (message != null) {
                MessageBuffer msg = new MessageBuffer(message);
                reason = msg.getString();
            }

            for (SimpleClientChannel channel : channels.values()) {
                try {
                    channel.left();
View Full Code Here

        /**
         * {@inheritDoc}
         */
        public void receivedMessage(byte[] message) {
            try {
                MessageBuffer msg = new MessageBuffer(message);
               
                if (logger.isLoggable(Level.FINER)) {
                    String logMessage = String.format(
                        "Message length:%d", message.length);
                    logger.log(Level.FINER, logMessage);
View Full Code Here

     * <li> (String) hostname
     * <li> (int) port
     * </ul>
     */
    public byte[] getConnectionData() {
        MessageBuffer buf =
                new MessageBuffer(MessageBuffer.getSize(hostName) + 4);
        buf.putString(hostName).
            putInt(listeningPort);
        return buf.getBuffer();
    }
View Full Code Here

    /** {@inheritDoc} */
    public void channelJoin(
  String name, BigInteger channelId, Delivery delivery)
    {
  byte[] channelIdBytes = channelId.toByteArray();
  MessageBuffer buf =
      new MessageBuffer(1 + MessageBuffer.getSize(name) +
            channelIdBytes.length);
  buf.putByte(SimpleSgsProtocol.CHANNEL_JOIN).
      putString(name).
      putBytes(channelIdBytes);
  writeOrEnqueueIfLoginNotHandled(ByteBuffer.wrap(buf.getBuffer()));
    }
View Full Code Here

    /**
     * Notifies the associated client that the previous login attempt was
     * successful.
     */
    protected void loginSuccess() {
  MessageBuffer buf = new MessageBuffer(1 + reconnectKey.length);
  buf.putByte(SimpleSgsProtocol.LOGIN_SUCCESS).
      putBytes(reconnectKey);
  writeToWriteHandler(ByteBuffer.wrap(buf.getBuffer()));
  flushMessageQueue();
    }
View Full Code Here

        for (ProtocolDescriptor descriptor : descriptors) {
            if (acceptor.getDescriptor().supportsProtocol(descriptor)) {
    byte[] redirectionData =
        ((SimpleSgsProtocolDescriptor) descriptor).
            getConnectionData();
    MessageBuffer buf =
        new MessageBuffer(1 + redirectionData.length);
    buf.putByte(SimpleSgsProtocol.LOGIN_REDIRECT).
        putBytes(redirectionData);
    writeToWriteHandler(ByteBuffer.wrap(buf.getBuffer()));
    flushMessageQueue();
    acceptor.monitorDisconnection(this);
                return;
            }
        }
View Full Code Here

     *    login request, or {@code null}
     */
    private void loginFailure(String reason, Throwable ignore) {
  // for now, override specified reason.
  reason = DEFAULT_LOGIN_FAILED_REASON;
        MessageBuffer buf =
      new MessageBuffer(1 + MessageBuffer.getSize(reason));
        buf.putByte(SimpleSgsProtocol.LOGIN_FAILURE).
            putString(reason);
        writeToWriteHandler(ByteBuffer.wrap(buf.getBuffer()));
  flushMessageQueue();
  acceptor.monitorDisconnection(this);
    }
View Full Code Here

        }

  /** Processes the received message. */
        private void bytesReceived(byte[] buffer) {

      MessageBuffer msg = new MessageBuffer(buffer);
      byte opcode = msg.getByte();

      if (logger.isLoggable(Level.FINEST)) {
    logger.log(
         Level.FINEST,
        "processing opcode 0x{0}",
        Integer.toHexString(opcode));
      }
     
      switch (opcode) {
   
      case SimpleSgsProtocol.LOGIN_REQUEST:

          byte version = msg.getByte();
          if (version != SimpleSgsProtocol.VERSION) {
              if (logger.isLoggable(Level.SEVERE)) {
                  logger.log(Level.SEVERE,
                      "got protocol version:{0}, " +
                      "expected {1}", version, SimpleSgsProtocol.VERSION);
              }
        disconnect();
              break;
          }

    final String name = msg.getString();
    final String password = msg.getString();

    try {
        identity = acceptor.authenticate(name, password);
    } catch (Exception e) {
        logger.logThrow(
      Level.FINEST, e,
      "login authentication failed for name:{0}", name);
        loginFailure("login failed", e);
       
        break;
    }

    listener.newLogin(
         identity, SimpleSgsProtocolImpl.this, new LoginHandler());
   
                // Resume reading immediately
    read();

    break;
   
      case SimpleSgsProtocol.SESSION_MESSAGE:
    ByteBuffer clientMessage =
        ByteBuffer.wrap(msg.getBytes(msg.limit() - msg.position()));
    if (protocolHandler == null) {
        // ignore message before authentication
        if (logger.isLoggable(Level.FINE)) {
      logger.log(
          Level.FINE,
          "Dropping early session message:{0} " +
          "for protocol:{1}",
          HexDumper.format(clientMessage, 0x50),
          SimpleSgsProtocolImpl.this);
        }
        return;
    }

    // TBD: schedule a task to process this message?
    protocolHandler.sessionMessage(clientMessage,
                 new RequestHandler());
    break;

      case SimpleSgsProtocol.CHANNEL_MESSAGE:
    BigInteger channelRefId =
        new BigInteger(1, msg.getBytes(msg.getShort()));
    ByteBuffer channelMessage =
        ByteBuffer.wrap(msg.getBytes(msg.limit() - msg.position()));
    if (protocolHandler == null) {
        // ignore message before authentication
        if (logger.isLoggable(Level.FINE)) {
      logger.log(
          Level.FINE,
View Full Code Here

                if (!connector.isConnected()) {
        String reason =
      connectFailureMessage != null ?
      connectFailureMessage :
      DEFAULT_CONNECT_FAILURE_MESSAGE;
        MessageBuffer buf =
      new MessageBuffer(MessageBuffer.getSize(reason));
        buf.putString(reason);
        listener.disconnected(false, buf.getBuffer());
                    if (!connectComplete) {
      try {
          connector.shutdown();
      } catch (IllegalStateException e) {
          // ignore; connect attempt may have completed
View Full Code Here

TOP

Related Classes of com.sun.sgs.impl.sharedutil.MessageBuffer

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.