net.kwfgrid.gwes.uiproxy
Class UIProxyImpl

java.lang.Object
  extended by net.kwfgrid.gwes.uiproxy.UIProxyImpl
All Implemented Interfaces:
UIProxy

public class UIProxyImpl
extends Object
implements UIProxy

The UIProxy. Facade for buffers, subscription handler and leasing system. The current implementation has no sophisticating synchronization management. This may lead to performance issues with multiple clients and buffers and should be fixed in the future.


Nested Class Summary
protected  class UIProxyImpl.Lease
           
 
Field Summary
protected  BufferFactory _bfact
           
protected  HashMapOfMaps _clients
          clientid -> bufferids -> buffer.
protected  MessageCodec _codec
           
protected  HashMap _leases
          clientid -> lease
protected  int _leasetime
           
protected  SubscriptionHandler _shandler
           
protected  HashMapOfMaps _subscriptions
          clientid -> bufferids -> subscription
static int DEFAULT_LEASE_TIME
           
 
Constructor Summary
UIProxyImpl(BufferFactory bfact, MessageCodec codec, SubscriptionHandler shandler)
           
 
Method Summary
 void disposeBuffer(String clientid, String bufferid)
          Dispose a buffer.
 void disposeClient(String clientid)
          Dispose a whole client.
protected  Buffer getBuffer(String clientid, String bufferid)
           
 int getLeaseTime()
           
 String[] poll(String clientid, String bufferid)
          Poll all buffered notifications for the specified client and buffer.
 void renewLease(String clientid)
          Renew the lease for the specified client.
 void setBufferProperty(String clientid, String bufferid, String key, String value)
          Set a property of a buffer.
 void setLeaseTime(int time)
           
 String subscribe(String clientid, String subscription, String buffertype, String[] propkeys, String[] propvalues)
          Subscribe for messages at a publisher.
protected  void timeout(String clientid)
          Called if a lease has timed out.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LEASE_TIME

public static final int DEFAULT_LEASE_TIME
See Also:
Constant Field Values

_clients

protected HashMapOfMaps _clients
clientid -> bufferids -> buffer.


_subscriptions

protected HashMapOfMaps _subscriptions
clientid -> bufferids -> subscription


_leases

protected HashMap _leases
clientid -> lease


_bfact

protected BufferFactory _bfact

_shandler

protected SubscriptionHandler _shandler

_codec

protected MessageCodec _codec

_leasetime

protected int _leasetime
Constructor Detail

UIProxyImpl

public UIProxyImpl(BufferFactory bfact,
                   MessageCodec codec,
                   SubscriptionHandler shandler)
Method Detail

setLeaseTime

public void setLeaseTime(int time)

getLeaseTime

public int getLeaseTime()

getBuffer

protected Buffer getBuffer(String clientid,
                           String bufferid)

subscribe

public String subscribe(String clientid,
                        String subscription,
                        String buffertype,
                        String[] propkeys,
                        String[] propvalues)
                 throws SubscriptionFailed
Subscribe for messages at a publisher. This will instantiate a buffer which stores the notification provided by the publisher. The specification of the subuscription must conform to the format which is defined by the SubscriptionHandler of the UIProxy.

Specified by:
subscribe in interface UIProxy
Parameters:
clientid - The UUID of the client.
subscription - Specification of the subscription.
buffertype - The type of the buffer to be created.
propkeys - The keys of the properties of the buffer, same index as propvalues.
propvalues - The values of the properties of the buffer, same index as propkeys.
Returns:
The UUID of the newly created buffer. Needed to poll notifications from that buffer.
Throws:
SubscriptionFailed - If the subscription failed.

renewLease

public void renewLease(String clientid)
Renew the lease for the specified client. If the client is unknown the request is silently discarded.

Specified by:
renewLease in interface UIProxy
Parameters:
clientid - The UUID of the client.

setBufferProperty

public void setBufferProperty(String clientid,
                              String bufferid,
                              String key,
                              String value)
                       throws BufferException
Set a property of a buffer. Calling this method will also renew the lease for the specified client. If the client is not the creator of the buffer, this method will silently discard the request.

Specified by:
setBufferProperty in interface UIProxy
Parameters:
clientid - The UUID of the client.
bufferid - The UUID of the buffer.
key - The name of the property.
value - The value of the property
Throws:
BufferException - If an exception occured when setting the property.

disposeBuffer

public void disposeBuffer(String clientid,
                          String bufferid)
Dispose a buffer. Calling this method will also renew the lease for the specified client. If the client is not the creator of the buffer, this method will silently discard the request.

Specified by:
disposeBuffer in interface UIProxy
Parameters:
clientid - The UUID of the client.
bufferid - The UUID of the buffer.

disposeClient

public void disposeClient(String clientid)
Dispose a whole client. This will free all resources associated with the client. If the client is unknown the request will be silently discarded.

Specified by:
disposeClient in interface UIProxy
Parameters:
clientid - The UUID of the client.

timeout

protected void timeout(String clientid)
Called if a lease has timed out. Disposes the client.


poll

public String[] poll(String clientid,
                     String bufferid)
              throws CodecException,
                     BufferException,
                     UnknownClientException,
                     UnknownBufferException
Poll all buffered notifications for the specified client and buffer. Calling this method will also renew the lease for the specified client. If the client is not the creator of the buffer, this method will silently discard the request and return an empty collection.

Specified by:
poll in interface UIProxy
Returns:
A collection of all buffered notifications from the specified buffer.
Throws:
BufferException - If a exception occured at the buffer when handling a message. In that case the client will have to create a new Buffer.
UnknownClientException - If the specified client is unknown to the UIProxy. This may also happen if the lease has timed out for the specified client.
UnknownBufferException - If the specified buffer is unknown to the UIProxy. This may also happen if the buffer previously encountered a BufferException. specified client.
CodecException


Copyright © 2005-2011 Fraunhofer FIRST. All Rights Reserved.