org.openorb.net
Class ServerManagerImpl

java.lang.Object
  |
  +--org.openorb.net.ServerManagerImpl
All Implemented Interfaces:
ServerManager

public class ServerManagerImpl
extends java.lang.Object
implements ServerManager

This class is the controler for most server side operations. It is responsible for registration and thread management for server protocols and channels, dispatch and thread management for requests, object reference construction and generates the adapter managers allowing flow control for adapters.

Author:
Unknown

Inner Class Summary
 class ServerManagerImpl.AdapterManagerImpl
          This class provides an implementation for the AdapterManager interface.
 
Inner classes inherited from class org.openorb.net.ServerManager
ServerManager.AdapterManager
 
Constructor Summary
ServerManagerImpl(ORB orb)
          Construct new server manager.
 
Method Summary
 void channel_reaper()
          This fuction runs in a separate thread and cleans up any channels which are not used for a long time.
 AdapterManager create_adapter_manager()
          Create an adapter manager.
 byte[] create_cacheable_object_key(boolean use_suid, byte[][] parts)
          This function is used by adapters to generate a key which will participate in adapter lookup short-circuiting.
 void enqueue_request(ServerRequest request)
          Begin dispatch sequence for incoming request.
 byte[][] extract_cacheable_object_key(byte[] object_key)
          Extract the component parts of a cacheable object_key.
 ObjectAdapter find_adapter(byte[] object_key)
          This function finds an adapter for the specified object id.
 java.lang.Object[] get_protocol_ids()
          Return the array of registered protocols.
 boolean is_cacheable_object_key(byte[] object_key)
          Returns true if the given object_key can be used in the cache.
 boolean is_local_cacheable_object_key(byte[] object_key)
          Returns true if the given object_key is cacheable and was created by this server.
 boolean is_suid_object_key(byte[] object_key)
          Returns true if the given object key has a persistent target.
 ORB orb()
          Return the orb.
 void protocol_listening(ServerProtocol protocol)
          This is called when a server protocol begins listening.
 void protocol_not_listening(ServerProtocol protocol, boolean paused)
          This is called when a server protocol is no longer listening.
 void register_adapter(byte[] aid, ObjectAdapter adapter)
          Register an adapter.
 void register_channel(ServerChannel channel)
          This operation occours when a protocol accepts a new incoming channel.
 void register_protocol(int profile_tag, ServerProtocol protocol)
          Register a server protocol.
 boolean serve_request(boolean wait)
          This is called from orb.perform_work, it serves a single request.
 void setMaxManagerHeldRequests(int maxManagerHeldRequests)
          Maximum number of requests which may be held by an adapter in the HOLDING state.
 void setMaxQueueSize(int maxQueueSize)
          Set maximum queue size.
 void setThreadPoolLimits(int min, int max)
          Set thread pool size ranges.
 void shutdown(boolean wait_for_complete)
          Spawns a thread to do the shutdown if wait_for_complete is false.
 void startup(boolean block, boolean allowPool)
          Start the thread groups for server io operations and for channel reaping.
 void unregister_adapter(byte[] aid)
          Unregister an adapter.
 void unregister_channel(ServerChannel channel)
          Called when a channel enters the closed state.
 boolean work_pending()
          Returns true if there are requests waiting in the incomming request queue for resources.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServerManagerImpl

public ServerManagerImpl(ORB orb)
Construct new server manager. There should be one of these objects per orb.
Parameters:
orb - The controling orb.
Method Detail

orb

public ORB orb()
Return the orb.
Specified by:
orb in interface ServerManager
Returns:
orb associated with the server manager.

setThreadPoolLimits

public void setThreadPoolLimits(int min,
                                int max)
Set thread pool size ranges. The thread pool size will be somewhere within this range, depending on load.
Specified by:
setThreadPoolLimits in interface ServerManager
Parameters:
min - minimum size for thread pool. Must be greater than 0 and less than max.
max - maximum thread pool size. If this is 0 then requests will only be processed when the orb.perform_work function is called. Must be greater than 0.

setMaxQueueSize

public void setMaxQueueSize(int maxQueueSize)
Set maximum queue size. If the queue grows to this size then new incoming requests will be rejected with a TRANSIENT exception. Changing this value downwards will not result in queued requests being destroyed.
Specified by:
setMaxQueueSize in interface ServerManager
Parameters:
maxQueueSize - maximum queue size. Must be greater than 1. Values should be several times the maximum thread pool size.

setMaxManagerHeldRequests

public void setMaxManagerHeldRequests(int maxManagerHeldRequests)
Maximum number of requests which may be held by an adapter in the HOLDING state. Changes to this value will only affect newly created object adapters.
Specified by:
setMaxManagerHeldRequests in interface ServerManager
Parameters:
maxAdapterHeldRequests - ceiling on adapter held requests. Individial adapter managers may modify this value downwards. Use 0 to dissallow the adapter holding state, and Integer.MAX_VALUE for no limit.

create_cacheable_object_key

public byte[] create_cacheable_object_key(boolean use_suid,
                                          byte[][] parts)
This function is used by adapters to generate a key which will participate in adapter lookup short-circuiting.
Specified by:
create_cacheable_object_key in interface ServerManager

extract_cacheable_object_key

public byte[][] extract_cacheable_object_key(byte[] object_key)
Extract the component parts of a cacheable object_key. Returns null if is_cacheable_object_key would return false.
Specified by:
extract_cacheable_object_key in interface ServerManager

is_cacheable_object_key

public boolean is_cacheable_object_key(byte[] object_key)
Returns true if the given object_key can be used in the cache.
Specified by:
is_cacheable_object_key in interface ServerManager

is_suid_object_key

public boolean is_suid_object_key(byte[] object_key)
Returns true if the given object key has a persistent target.
Specified by:
is_suid_object_key in interface ServerManager

is_local_cacheable_object_key

public boolean is_local_cacheable_object_key(byte[] object_key)
Returns true if the given object_key is cacheable and was created by this server.
Specified by:
is_local_cacheable_object_key in interface ServerManager

register_protocol

public void register_protocol(int profile_tag,
                              ServerProtocol protocol)
Register a server protocol. This registers the protocol for purposes of constructing IORs. When the protocol begins listening it should call protocol_listening. If multiple protocols are registered with the same tag value, or a profile registered with multiple tag values then the constructed IOR will contain multiple profiles, one from each distinct registered protocol/tag pair. Registering the same protocol with the same tag more than once will not result in multiple profiles.
Specified by:
register_protocol in interface ServerManager
Parameters:
profile_tag - Profile tag of IOR consturcted with the protocol.
protocol - The server protocol.

get_protocol_ids

public java.lang.Object[] get_protocol_ids()
Return the array of registered protocols.
Specified by:
get_protocol_ids in interface ServerManager

protocol_listening

public void protocol_listening(ServerProtocol protocol)
This is called when a server protocol begins listening. Thread resources are allocated to call the listen function regularly.
Specified by:
protocol_listening in interface ServerManager
Parameters:
protocol - The server protocol.

protocol_not_listening

public void protocol_not_listening(ServerProtocol protocol,
                                   boolean paused)
This is called when a server protocol is no longer listening. It stops getting serviced by the pool thread.
Specified by:
protocol_not_listening in interface ServerManager
Parameters:
protocol - The server protocol.
paused - If true when the server side is shut down close will still be called on the protocol.

register_channel

public void register_channel(ServerChannel channel)
This operation occours when a protocol accepts a new incoming channel.
Specified by:
register_channel in interface ServerManager

unregister_channel

public void unregister_channel(ServerChannel channel)
Called when a channel enters the closed state. Returns once all channel threads have completed their work cycles.
Specified by:
unregister_channel in interface ServerManager

channel_reaper

public void channel_reaper()
This fuction runs in a separate thread and cleans up any channels which are not used for a long time.
Specified by:
channel_reaper in interface ServerManager

find_adapter

public ObjectAdapter find_adapter(byte[] object_key)
This function finds an adapter for the specified object id. If an adapter for an object with the given object id cannot be found this returns null. This varient of the find_adapter function is used by local bindings. It ignores the state of the adapter manager and any single threading policies, If the target adapter or one of it's ancestors is in the process of being destroyed this will wait until the destruction is complete.
Specified by:
find_adapter in interface ServerManager
Returns:
The adapter specified in the object key.

register_adapter

public void register_adapter(byte[] aid,
                             ObjectAdapter adapter)
Register an adapter. If the specified adapter is already registered no change occours. This will occour automaticaly for child adapters of some root adapter.
Specified by:
register_adapter in interface ServerManager

unregister_adapter

public void unregister_adapter(byte[] aid)
Unregister an adapter. If the specified adapter is not registered no change occours. If an adapter throws an AdapterDestroyed exception it must eventualy call this function to continue processing the held requests.
Specified by:
unregister_adapter in interface ServerManager

create_adapter_manager

public AdapterManager create_adapter_manager()
Create an adapter manager.
Specified by:
create_adapter_manager in interface ServerManager

enqueue_request

public void enqueue_request(ServerRequest request)
Begin dispatch sequence for incoming request. This will enqueue the request and return immediatly.
Specified by:
enqueue_request in interface ServerManager

work_pending

public boolean work_pending()
Description copied from interface: ServerManager
Returns true if there are requests waiting in the incomming request queue for resources.
Specified by:
work_pending in interface ServerManager

serve_request

public boolean serve_request(boolean wait)
This is called from orb.perform_work, it serves a single request.
Specified by:
serve_request in interface ServerManager
Returns:
true if a request was served, false if the queue is empty

startup

public void startup(boolean block,
                    boolean allowPool)
Start the thread groups for server io operations and for channel reaping. The thread group for channel reaping is only started when a closing time for channel reaping greater 0 is specified.
Specified by:
startup in interface ServerManager
Following copied from interface: org.openorb.net.ServerManager
Parameters:
block - true if this funtion should not return until the server is shut down.
allowPool - true if the thread pool is allowed. Once a call the thread pool has been started it cannot be dissallowed in the future by calling this with a false.

shutdown

public void shutdown(boolean wait_for_complete)
Spawns a thread to do the shutdown if wait_for_complete is false.
Specified by:
shutdown in interface ServerManager
Following copied from interface: org.openorb.net.ServerManager
Parameters:
wait_for_complete - If true wait until all channels have closed and incomming requests have finished processing. If false all active requests will be canceled and the function will return once connections have shutdown.