ch.ethz.iks.r_osgi.impl
Class ChannelEndpointImpl

java.lang.Object
  extended by ch.ethz.iks.r_osgi.impl.ChannelEndpointImpl
All Implemented Interfaces:
ChannelEndpoint

public final class ChannelEndpointImpl
extends java.lang.Object
implements ChannelEndpoint

The endpoint of a network channel encapsulates most of the communication logic like sending of messages, service method invocation, timestamp synchronization, and event delivery.

Endpoints exchange symmetric leases when they are established. These leases contain the statements of supply and demand. The peer states the services it offers and the event topics it is interested in. Whenever one of these statements undergo a change, a lease update has to be sent. Leases expire with the closing of the network channel and the two endpoints.

The network transport of channels is modular and exchangeable. Services can state the supported protocols in their service uri. R-OSGi maintains a list of network channel factories and the protocols they support. Each channel uses exactly one protocol.

When the network channel breaks down, the channel endpoint tries to reconnect and to restore the connection. If this is not possible (for instance, because the other endpoint is not available any more, the endpoint is unregistered.

Author:
Jan S. Rellermeyer, ETH Zurich

Field Summary
protected  java.util.Map callbacks
          the callback register
protected  NetworkChannel networkChannel
          the channel.
protected  java.util.HashMap proxyBundles
          map of service uri -> proxy bundle.
 
Method Summary
 void dispose()
          dispose the channel.
 ch.ethz.iks.r_osgi.impl.TimeOffset getOffset()
          get the temporal offset of a remote peer.
 java.util.Dictionary getPresentationProperties(java.lang.String serviceID)
          get the attributes for the presentation of the service.
 java.util.Dictionary getProperties(java.lang.String serviceID)
          get the attributes of a service.
 URI getRemoteAddress()
          get the channel URI.
 java.lang.Object invokeMethod(java.lang.String service, java.lang.String methodSignature, java.lang.Object[] args)
          invoke a method on the remote host.
 boolean isConnected()
           
 int readStream(short streamID)
          read a byte from the input stream on the peer identified by id.
 int readStream(short streamID, byte[] b, int off, int len)
          read to an array from the input stream on the peer identified by id.
 void receivedMessage(RemoteOSGiMessage msg)
          process a recieved message.
 java.lang.String toString()
           
 void trackRegistration(java.lang.String serviceID, org.osgi.framework.ServiceRegistration reg)
          track the registration of a proxy service.
 void untrackRegistration(java.lang.String serviceID)
          untrack the registration of a proxy service.
 void writeStream(short streamID, byte[] b, int off, int len)
          write bytes from array to output stream on the peer identified by id.
 void writeStream(short streamID, int b)
          write a byte to the output stream on the peer identified by id.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

networkChannel

protected NetworkChannel networkChannel
the channel.


callbacks

protected final java.util.Map callbacks
the callback register


proxyBundles

protected final java.util.HashMap proxyBundles
map of service uri -> proxy bundle. If the endpoint is closed, the proxies are unregistered.

Method Detail

receivedMessage

public void receivedMessage(RemoteOSGiMessage msg)
process a recieved message. Called by the channel.

Specified by:
receivedMessage in interface ChannelEndpoint
Parameters:
msg - the received message.
See Also:
ch.ethz.iks.r_osgi.channels.ChannelEndpoint#receivedMessage(ch.ethz.iks.r_osgi.RemoteOSGiMessage)

invokeMethod

public java.lang.Object invokeMethod(java.lang.String service,
                                     java.lang.String methodSignature,
                                     java.lang.Object[] args)
                              throws java.lang.Throwable
invoke a method on the remote host. This function is used by all proxy bundles.

Specified by:
invokeMethod in interface ChannelEndpoint
Parameters:
service - the service uri.
methodSignature - the method signature.
args - the method parameter.
Returns:
the result of the remote method invokation.
Throws:
java.lang.Throwable - can throw any exception that the original method can throw, plus RemoteOSGiException.
See Also:
ch.ethz.iks.r_osgi.Remoting#invokeMethod(java.lang.String, java.lang.String, java.lang.String, java.lang.Object[])

getProperties

public java.util.Dictionary getProperties(java.lang.String serviceID)
get the attributes of a service. This function is used to simplify proxy bundle generation.

Specified by:
getProperties in interface ChannelEndpoint
Parameters:
serviceID - the serviceID of the remote service.
Returns:
the service attributes.

getPresentationProperties

public java.util.Dictionary getPresentationProperties(java.lang.String serviceID)
get the attributes for the presentation of the service. This function is used by proxies that support ServiceUI presentations.

Specified by:
getPresentationProperties in interface ChannelEndpoint
Parameters:
serviceID - the serviceID of the remote service.
Returns:
the presentation attributes.

trackRegistration

public void trackRegistration(java.lang.String serviceID,
                              org.osgi.framework.ServiceRegistration reg)
track the registration of a proxy service.

Specified by:
trackRegistration in interface ChannelEndpoint
Parameters:
serviceID - the service ID.
reg - the service registration.

untrackRegistration

public void untrackRegistration(java.lang.String serviceID)
untrack the registration of a proxy service.

Specified by:
untrackRegistration in interface ChannelEndpoint
Parameters:
serviceID - the service ID.

getOffset

public ch.ethz.iks.r_osgi.impl.TimeOffset getOffset()
                                             throws RemoteOSGiException
get the temporal offset of a remote peer.

Returns:
the TimeOffset.
Throws:
RemoteOSGiException - in case of network errors.

dispose

public void dispose()
dispose the channel.

Specified by:
dispose in interface ChannelEndpoint

isConnected

public boolean isConnected()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

readStream

public int readStream(short streamID)
               throws java.io.IOException
read a byte from the input stream on the peer identified by id.

Parameters:
streamID - the ID of the stream.
Returns:
result of the read operation.
Throws:
java.io.IOException - when an IOException occurs.

readStream

public int readStream(short streamID,
                      byte[] b,
                      int off,
                      int len)
               throws java.io.IOException
read to an array from the input stream on the peer identified by id.

Parameters:
streamID - the ID of the stream.
b - the array to write the result to.
off - the offset for the destination array.
len - the number of bytes to read.
Returns:
number of bytes actually read.
Throws:
java.io.IOException - when an IOException occurs.

writeStream

public void writeStream(short streamID,
                        int b)
                 throws java.io.IOException
write a byte to the output stream on the peer identified by id.

Parameters:
streamID - the ID of the stream.
b - the value.
Throws:
java.io.IOException - when an IOException occurs.

writeStream

public void writeStream(short streamID,
                        byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
write bytes from array to output stream on the peer identified by id.

Parameters:
streamID - the ID of the stream.
b - the source array.
off - offset into the source array.
len - number of bytes to copy.
Throws:
java.io.IOException - when an IOException occurs.

getRemoteAddress

public URI getRemoteAddress()
get the channel URI.

Specified by:
getRemoteAddress in interface ChannelEndpoint
Returns:
the channel ID.


Copyright © 2009 IKS, ETH Zurich. All Rights Reserved.