com.sun.jmx.remote.socket
Class SocketConnection

java.lang.Object
  extended by com.sun.jmx.remote.socket.SocketConnection
All Implemented Interfaces:
SocketConnectionIf, MessageConnection

public class SocketConnection
extends Object
implements SocketConnectionIf, MessageConnection

This class uses TCP sockets to implement a JMX client MessageConnection.


Constructor Summary
SocketConnection(Socket socket)
          Constructs a TCP socket client connection from a given socket.
SocketConnection(String addr, int port)
          Constructs a TCP socket client connection from the given address and port.
 
Method Summary
 void close()
          Terminates this object connection.
 void connect(Map env)
          Establish the connection.
 String getConnectionId()
          The ID for this connection.
 Socket getSocket()
          Returns a reference to the underlying socket.
 Message readMessage()
          Reads a Message object from the other end of the connection.
 void replaceStreams(InputStream is, OutputStream os)
          Replaces the current socket's input/output streams by the ones provided.
 void setSocket(Socket s)
          Replaces the underlying socket.
 void setSubject(Subject subject)
          Sets the subject authenticated through this socket connection.
 void writeMessage(Message msg)
          Writes a Message object to the other end of the connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SocketConnection

public SocketConnection(Socket socket)
                 throws IOException
Constructs a TCP socket client connection from a given socket.

Parameters:
socket - a TCP socket created by a user.
Throws:
IOException

SocketConnection

public SocketConnection(String addr,
                        int port)
                 throws IOException
Constructs a TCP socket client connection from the given address and port.

Parameters:
addr - the server host address.
port - the server port.
Throws:
IOException
Method Detail

connect

public void connect(Map env)
             throws IOException
Description copied from interface: MessageConnection

Establish the connection. This method must be called before any other method of this interface. The behavior is unspecified if not.

Specified by:
connect in interface MessageConnection
Parameters:
env - the properties of the connection.
Throws:
IOException - if the connection cannot be made.

getSocket

public Socket getSocket()
Returns a reference to the underlying socket.

Specified by:
getSocket in interface SocketConnectionIf

setSocket

public void setSocket(Socket s)
               throws IOException
Replaces the underlying socket.

Specified by:
setSocket in interface SocketConnectionIf
Throws:
IOException

replaceStreams

public void replaceStreams(InputStream is,
                           OutputStream os)
                    throws IOException
Replaces the current socket's input/output streams by the ones provided.

Specified by:
replaceStreams in interface SocketConnectionIf
Throws:
IOException

setSubject

public void setSubject(Subject subject)
Sets the subject authenticated through this socket connection.

Specified by:
setSubject in interface SocketConnectionIf

readMessage

public Message readMessage()
                    throws IOException,
                           ClassNotFoundException
Description copied from interface: MessageConnection

Reads a Message object from the other end of the connection.

Specified by:
readMessage in interface MessageConnection
Returns:
the message got from the other end of the connection.
Throws:
IOException - if a message could not be read because of a communication problem.
ClassNotFoundException - If the class of a serialized object cannot be found.

writeMessage

public void writeMessage(Message msg)
                  throws IOException
Description copied from interface: MessageConnection

Writes a Message object to the other end of the connection.

Specified by:
writeMessage in interface MessageConnection
Parameters:
msg - the message to be written.
Throws:
IOException - if the message could not be written because of a communication problem.

close

public void close()
Description copied from interface: MessageConnection

Terminates this object connection. After calling this method, any current or new call to readMessage or MessageConnection.writeMessage(Message) should produce an IOException.

Specified by:
close in interface MessageConnection

getConnectionId

public String getConnectionId()
Description copied from interface: MessageConnection

The ID for this connection.

Specified by:
getConnectionId in interface MessageConnection
Returns:
the ID for this connection. This method can return null if the connection handshake is not yet complete.



Copyright © 2014 Terracotta, Inc.. All rights reserved.