org.sapia.ubik.net
Class SocketConnection

java.lang.Object
  extended by org.sapia.ubik.net.SocketConnection
All Implemented Interfaces:
Connection
Direct Known Subclasses:
SocketRmiConnection

public class SocketConnection
extends java.lang.Object
implements Connection

A Connection implemented through a Socket.

Author:
Yanick Duchesne
Copyright:
Copyright © 2002-2003 Sapia Open Source Software. All Rights Reserved.
License:
Read the license.txt file of the jar or visit the license page at the Sapia OSS web site

Field Summary
protected  TCPAddress _address
           
protected  java.io.ObjectInputStream _is
           
protected  long _lastReset
           
protected  java.lang.ClassLoader _loader
           
protected  java.io.ObjectOutputStream _os
           
protected  long _resetInterval
           
protected  java.net.Socket _sock
           
 
Constructor Summary
SocketConnection(java.net.Socket sock)
           
SocketConnection(java.net.Socket sock, java.lang.ClassLoader loader)
           
 
Method Summary
 void close()
          Closes this connection.
protected  void doSend(java.lang.Object toSend, java.io.ObjectOutputStream mos)
           
 java.io.InputStream getInputStream()
          Returns this instance's internal input stream.
 java.io.OutputStream getOuputStream()
          Returns this instance's internal output stream.
 ServerAddress getServerAddress()
          Returns "address" of the server with which this connection communicates.
protected  java.io.ObjectInputStream newInputStream(java.io.InputStream is, java.lang.ClassLoader loader)
          Template method internally called by this instance; the method should create an ObjectInputStream for the given parameters.
protected  java.io.ObjectOutputStream newOutputStream(java.io.OutputStream os, java.lang.ClassLoader loader)
          Template method internally called by this instance; the method should create an ObjectOutputStream for the given parameters.
protected  void readHeader(java.io.InputStream is, java.lang.ClassLoader loader)
           
 java.lang.Object receive()
          Receives an object from the server with which this connection communicates.
 void send(java.lang.Object o)
          Sends the given object to the server with which this connection communicates.
 void setResetInterval(long interval)
          Sets the interval at which this instance calls the reset method on the ObjectOutputStream that in uses internally for serializing objects.
protected  void writeHeader(java.io.OutputStream os, java.lang.ClassLoader loader)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_sock

protected java.net.Socket _sock

_address

protected TCPAddress _address

_loader

protected java.lang.ClassLoader _loader

_is

protected java.io.ObjectInputStream _is

_os

protected java.io.ObjectOutputStream _os

_lastReset

protected long _lastReset

_resetInterval

protected long _resetInterval
Constructor Detail

SocketConnection

public SocketConnection(java.net.Socket sock,
                        java.lang.ClassLoader loader)

SocketConnection

public SocketConnection(java.net.Socket sock)
Method Detail

setResetInterval

public void setResetInterval(long interval)
Sets the interval at which this instance calls the reset method on the ObjectOutputStream that in uses internally for serializing objects.

This instance performs the reset at every write, insuring that no stale object is cached by the underlying ObjectOutputStream.

Parameters:
interval - the interval (in millis) at which this instance calls the reset method of its ObjectOutputStream.

send

public void send(java.lang.Object o)
          throws java.io.IOException,
                 java.rmi.RemoteException
Description copied from interface: Connection
Sends the given object to the server with which this connection communicates.

Specified by:
send in interface Connection
Throws:
java.io.IOException
java.rmi.RemoteException
See Also:
Connection.send(Object)

receive

public java.lang.Object receive()
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException,
                                java.rmi.RemoteException
Description copied from interface: Connection
Receives an object from the server with which this connection communicates.

Specified by:
receive in interface Connection
Returns:
an Object.
Throws:
java.io.IOException
java.lang.ClassNotFoundException
java.rmi.RemoteException
See Also:
Connection.receive()

close

public void close()
Description copied from interface: Connection
Closes this connection.

Specified by:
close in interface Connection
See Also:
Connection.close()

getServerAddress

public ServerAddress getServerAddress()
Description copied from interface: Connection
Returns "address" of the server with which this connection communicates.

Specified by:
getServerAddress in interface Connection
Returns:
a ServerAddress.
See Also:
Connection.getServerAddress()

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Returns this instance's internal input stream.

Returns:
an InputStream.
Throws:
java.io.IOException

getOuputStream

public java.io.OutputStream getOuputStream()
                                    throws java.io.IOException
Returns this instance's internal output stream.

Returns:
an OutputStream.
Throws:
java.io.IOException

newOutputStream

protected java.io.ObjectOutputStream newOutputStream(java.io.OutputStream os,
                                                     java.lang.ClassLoader loader)
                                              throws java.io.IOException
Template method internally called by this instance; the method should create an ObjectOutputStream for the given parameters.

Parameters:
os - the OutputStream that the returned stream should wrap.
the - ClassLoader that this instance corresponds to.
Returns:
an ObjectOutputStream.
Throws:
java.io.IOException - if a problem occurs creating the desired object.

newInputStream

protected java.io.ObjectInputStream newInputStream(java.io.InputStream is,
                                                   java.lang.ClassLoader loader)
                                            throws java.io.IOException
Template method internally called by this instance; the method should create an ObjectInputStream for the given parameters.

The returned instance can use the passed in classloader to resolve the classes of the deserialized objects.

Parameters:
is - the InputStream that the returned stream should wrap.
the - ClassLoader that this instance corresponds to.
Returns:
an ObjectInputStream.
Throws:
java.io.IOException - if a problem occurs creating the desired object.
See Also:
ObjectInputStream.resolveClass(java.io.ObjectStreamClass)

doSend

protected void doSend(java.lang.Object toSend,
                      java.io.ObjectOutputStream mos)
               throws java.io.IOException
Throws:
java.io.IOException

writeHeader

protected void writeHeader(java.io.OutputStream os,
                           java.lang.ClassLoader loader)
                    throws java.io.IOException
Throws:
java.io.IOException

readHeader

protected void readHeader(java.io.InputStream is,
                          java.lang.ClassLoader loader)
                   throws java.io.IOException
Throws:
java.io.IOException


Copyright © 2010 Sapia OSS. All Rights Reserved.