com.cosylab.epics.caj
Class CAJContext

java.lang.Object
  extended by gov.aps.jca.Context
      extended by com.cosylab.epics.caj.CAJContext
All Implemented Interfaces:
CAJConstants, CAContext, LoggerProvider, gov.aps.jca.configuration.Configurable

public class CAJContext
extends gov.aps.jca.Context
implements CAContext, CAJConstants, gov.aps.jca.configuration.Configurable

Implementation of CAJ JCA Context.

Version:
$id$
Author:
Matej Sekoranja

Field Summary
protected  String addressList
          A space-separated list of broadcast address for process variable name resolution.
protected  boolean autoAddressList
          Define whether or not the network interfaces should be discovered at runtime.
protected  Map beaconHandlers
          Beacon handler map.
protected  float beaconPeriod
          Period in second between two beacon signals.
protected  BroadcastTransport broadcastTransport
          Broadcast transport needed for channel searches.
protected  CachedByteBufferAllocator cachedBufferAllocator
          Cached byte buffer allocator.
static String CAJ_SINGLE_THREADED_MODEL
          String value of the JVM property key to turn on single threaded model.
protected  IntHashMap channelsByCID
          Map of channels (keys are CIDs).
protected  Map channelsByName
          Map of channels (keys are names).
protected  float connectionTimeout
          If the context doesn't see a beacon from a server that it is connected to for connectionTimeout seconds then a state-of-health message is sent to the server over TCP/IP.
protected  CAConnector connector
          CA connector (creates CA virtual circuit).
protected  ArrayList contextExceptionListeners
          List of context exception listeners.
protected  ArrayList contextMessageListeners
          List of context message listeners.
protected  gov.aps.jca.event.EventDispatcher eventDispatcher
          Event dispatcher.
protected  LeaderFollowersThreadPool leaderFollowersThreadPool
          Leader/followers thread pool.
protected  Logger logger
          Context logger.
protected  int maxArrayBytes
          Length in bytes of the maximum array size that may pass through CA.
protected  IntHashMap pendingResponseRequests
          Map of pending response requests (keys are IOID).
protected  Reactor reactor
          Reactor.
protected  boolean registrationConfirmed
          Registration confirmation status.
protected  int repeaterPort
          Port number for the repeater to listen to.
protected  int serverPort
          Port number for the server to listen to.
protected  Timer timer
          Timer.
protected  CATransportRegistry transportRegistry
          CA transport (virtual circuit) registry.
static gov.aps.jca.Version VERSION
          Version.
 
Fields inherited from interface com.cosylab.epics.caj.CAJConstants
CAJ_DEBUG, CAJ_STRIP_HOSTNAME
 
Constructor Summary
CAJContext()
          Constructor.
 
Method Summary
 void addContextExceptionListener(gov.aps.jca.event.ContextExceptionListener l)
           
 void addContextMessageListener(gov.aps.jca.event.ContextMessageListener l)
           
 void attachCurrentThread()
           
 void beaconAnomalyNotify()
          Called each time beacon anomaly is detected.
protected  void checkState()
          Check context state and tries to establish necessary state.
 void configure(gov.aps.jca.configuration.Configuration configuration)
           
 gov.aps.jca.Channel createChannel(String name, gov.aps.jca.event.ConnectionListener l, short priority)
           
 void decrementPendingRequests(int usedSequenceNumberIO)
          Decrement pending requests counter.
 void destroy()
           
 void destroyChannel(CAJChannel channel, boolean force)
          Destroy channel.
 void flushIO()
           
 String getAddressList()
          Get search address list.
 CABeaconHandler getBeaconHandler(InetSocketAddress responseFrom)
          Get (and if necessary create) beacon handler.
 float getBeaconPeriod()
          Get beacon period (in seconds).
 int getBroadcastPort()
          Get broadcast port.
 BroadcastTransport getBroadcastTransport()
          Broadcast transport.
 CachedByteBufferAllocator getCachedBufferAllocator()
          Get cached byte allocator.
 CAJChannel getChannel(int channelID)
          Searches for a channel with given channel ID.
 CAJChannel getChannel(String name, short priority, boolean acquire)
          Searches for a channel with given channel name.
 gov.aps.jca.Channel[] getChannels()
           
 ChannelSearchManager getChannelSearchManager()
          Get channel search manager.
 float getConnectionTimeout()
          Get connection timeout (in seconds).
 gov.aps.jca.event.ContextExceptionListener[] getContextExceptionListeners()
           
 gov.aps.jca.event.ContextMessageListener[] getContextMessageListeners()
           
 gov.aps.jca.event.EventDispatcher getEventDispatcher()
          Get event dispatcher.
 int getLastReceivedSequenceNumber(int seqNo)
          Set last UDP recived sequence number.
 LeaderFollowersThreadPool getLeaderFollowersThreadPool()
          Get LF thread pool.
 Logger getLogger()
          Get logger.
 int getMaxArrayBytes()
          Get max size of payload.
 Reactor getReactor()
          Get context reactor.
 int getRepeaterPort()
          Get repeater port.
 ResponseRequest getResponseRequest(int ioid)
          Searches for a response request with given channel IOID.
 int getServerPort()
          Get server port.
 Timer getTimer()
          Get timer.
 CATransportRegistry getTransportRegistry()
          Get CA transport (virtual circuit) registry.
 gov.aps.jca.Version getVersion()
          Get context version.
 int incrementPendingRequests()
          Increment pending requests counter.
 void initialize()
           
protected  void initializeLogger()
          Initialize context logger.
 void invalidateLastReceivedSequence()
          Invalidate last (UDP) received sequence.
 boolean isAutoAddressList()
          Get auto search-list flag.
 boolean isDestroyed()
          Get destruction status.
 boolean isInitialized()
          Get initialization status.
 boolean isRegistrationConfirmed()
          Get repeater registration status.
protected  void loadConfiguration()
          Load configuration.
 void notifyException(gov.aps.jca.event.ContextExceptionEvent event)
          Notifies context listeners about exception.
 void pendEvent(double timeout)
           
 void pendIO(double timeout)
           
 void poll()
           
 void printInfo(PrintStream out)
           
 int registerResponseRequest(ResponseRequest request)
          Register response request.
 void removeContextExceptionListener(gov.aps.jca.event.ContextExceptionListener l)
           
 void removeContextMessageListener(gov.aps.jca.event.ContextMessageListener l)
           
 void repeaterConfirm(InetSocketAddress responseFrom)
          Repeater registration confirmation.
 void searchResponse(int cid, int sid, short type, int count, short minorRevision, InetSocketAddress serverAddress)
          Search response from server (channel found).
 void setLastReceivedSequenceNumber(int seqNo)
          Set last UDP recived sequence number.
 boolean testIO()
           
 ResponseRequest unregisterResponseRequest(ResponseRequest request)
          Unregister response request.
 
Methods inherited from class gov.aps.jca.Context
createChannel, createChannel, createChannel, dispose, printInfo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final gov.aps.jca.Version VERSION
Version.


CAJ_SINGLE_THREADED_MODEL

public static final String CAJ_SINGLE_THREADED_MODEL
String value of the JVM property key to turn on single threaded model.

See Also:
Constant Field Values

logger

protected Logger logger
Context logger.


addressList

protected String addressList
A space-separated list of broadcast address for process variable name resolution. Each address must be of the form: ip.number:port or host.name:port


autoAddressList

protected boolean autoAddressList
Define whether or not the network interfaces should be discovered at runtime.


connectionTimeout

protected float connectionTimeout
If the context doesn't see a beacon from a server that it is connected to for connectionTimeout seconds then a state-of-health message is sent to the server over TCP/IP. If this state-of-health message isn't promptly replied to then the context will assume that the server is no longer present on the network and disconnect.


beaconPeriod

protected float beaconPeriod
Period in second between two beacon signals.


repeaterPort

protected int repeaterPort
Port number for the repeater to listen to.


serverPort

protected int serverPort
Port number for the server to listen to.


maxArrayBytes

protected int maxArrayBytes
Length in bytes of the maximum array size that may pass through CA.


contextMessageListeners

protected ArrayList contextMessageListeners
List of context message listeners.


contextExceptionListeners

protected ArrayList contextExceptionListeners
List of context exception listeners.


eventDispatcher

protected gov.aps.jca.event.EventDispatcher eventDispatcher
Event dispatcher.


timer

protected Timer timer
Timer.


reactor

protected Reactor reactor
Reactor.


leaderFollowersThreadPool

protected LeaderFollowersThreadPool leaderFollowersThreadPool
Leader/followers thread pool.


registrationConfirmed

protected boolean registrationConfirmed
Registration confirmation status.


broadcastTransport

protected BroadcastTransport broadcastTransport
Broadcast transport needed for channel searches.


connector

protected CAConnector connector
CA connector (creates CA virtual circuit).


transportRegistry

protected CATransportRegistry transportRegistry
CA transport (virtual circuit) registry. This registry contains all active transports - connections to CA servers.


cachedBufferAllocator

protected CachedByteBufferAllocator cachedBufferAllocator
Cached byte buffer allocator. Used by transports which as send buffers.


channelsByCID

protected IntHashMap channelsByCID
Map of channels (keys are CIDs).


channelsByName

protected Map channelsByName
Map of channels (keys are names).


pendingResponseRequests

protected IntHashMap pendingResponseRequests
Map of pending response requests (keys are IOID).


beaconHandlers

protected Map beaconHandlers
Beacon handler map.

Constructor Detail

CAJContext

public CAJContext()
Constructor.

Method Detail

getVersion

public gov.aps.jca.Version getVersion()
Get context version.

Specified by:
getVersion in class gov.aps.jca.Context
See Also:
Context.getVersion()

initializeLogger

protected void initializeLogger()
Initialize context logger.


loadConfiguration

protected void loadConfiguration()
Load configuration.


configure

public void configure(gov.aps.jca.configuration.Configuration configuration)
               throws gov.aps.jca.configuration.ConfigurationException
Specified by:
configure in interface gov.aps.jca.configuration.Configurable
Throws:
gov.aps.jca.configuration.ConfigurationException
See Also:
Configurable.configure(gov.aps.jca.configuration.Configuration)

getContextMessageListeners

public gov.aps.jca.event.ContextMessageListener[] getContextMessageListeners()
                                                                      throws IllegalStateException
Specified by:
getContextMessageListeners in class gov.aps.jca.Context
Throws:
IllegalStateException
See Also:
Context.getContextMessageListeners()

addContextMessageListener

public void addContextMessageListener(gov.aps.jca.event.ContextMessageListener l)
                               throws gov.aps.jca.CAException,
                                      IllegalStateException
Specified by:
addContextMessageListener in class gov.aps.jca.Context
Throws:
gov.aps.jca.CAException
IllegalStateException
See Also:
Context.addContextMessageListener(gov.aps.jca.event.ContextMessageListener)

removeContextMessageListener

public void removeContextMessageListener(gov.aps.jca.event.ContextMessageListener l)
                                  throws gov.aps.jca.CAException,
                                         IllegalStateException
Specified by:
removeContextMessageListener in class gov.aps.jca.Context
Throws:
gov.aps.jca.CAException
IllegalStateException
See Also:
Context.removeContextMessageListener(gov.aps.jca.event.ContextMessageListener)

getContextExceptionListeners

public gov.aps.jca.event.ContextExceptionListener[] getContextExceptionListeners()
                                                                          throws IllegalStateException
Specified by:
getContextExceptionListeners in class gov.aps.jca.Context
Throws:
IllegalStateException
See Also:
Context.getContextExceptionListeners()

addContextExceptionListener

public void addContextExceptionListener(gov.aps.jca.event.ContextExceptionListener l)
                                 throws gov.aps.jca.CAException,
                                        IllegalStateException
Specified by:
addContextExceptionListener in class gov.aps.jca.Context
Throws:
gov.aps.jca.CAException
IllegalStateException
See Also:
Context.addContextExceptionListener(gov.aps.jca.event.ContextExceptionListener)

removeContextExceptionListener

public void removeContextExceptionListener(gov.aps.jca.event.ContextExceptionListener l)
                                    throws gov.aps.jca.CAException,
                                           IllegalStateException
Specified by:
removeContextExceptionListener in class gov.aps.jca.Context
Throws:
gov.aps.jca.CAException
IllegalStateException
See Also:
Context.removeContextExceptionListener(gov.aps.jca.event.ContextExceptionListener)

notifyException

public void notifyException(gov.aps.jca.event.ContextExceptionEvent event)
Notifies context listeners about exception.

Parameters:
event - context exception event to be fired.

checkState

protected void checkState()
                   throws gov.aps.jca.CAException,
                          IllegalStateException
Check context state and tries to establish necessary state.

Throws:
gov.aps.jca.CAException
IllegalStateException

initialize

public void initialize()
                throws gov.aps.jca.CAException
Overrides:
initialize in class gov.aps.jca.Context
Throws:
gov.aps.jca.CAException
See Also:
Context.initialize()

destroy

public void destroy()
             throws gov.aps.jca.CAException,
                    IllegalStateException
Specified by:
destroy in class gov.aps.jca.Context
Throws:
gov.aps.jca.CAException
IllegalStateException
See Also:
Context.destroy()

createChannel

public gov.aps.jca.Channel createChannel(String name,
                                         gov.aps.jca.event.ConnectionListener l,
                                         short priority)
                                  throws gov.aps.jca.CAException,
                                         IllegalStateException
Specified by:
createChannel in class gov.aps.jca.Context
Throws:
gov.aps.jca.CAException
IllegalStateException
See Also:
Context.createChannel(java.lang.String, gov.aps.jca.event.ConnectionListener, short)

destroyChannel

public void destroyChannel(CAJChannel channel,
                           boolean force)
                    throws gov.aps.jca.CAException,
                           IllegalStateException
Destroy channel.

Parameters:
channel -
force -
Throws:
gov.aps.jca.CAException
IllegalStateException

getChannel

public CAJChannel getChannel(int channelID)
Searches for a channel with given channel ID.

Parameters:
channelID - CID.
Returns:
channel with given CID, null if non-existant.

getChannel

public CAJChannel getChannel(String name,
                             short priority,
                             boolean acquire)
Searches for a channel with given channel name.

Parameters:
name - channel name.
priority - channel priority.
acquire - whether to acquire ownership (increment ref. counting)
Returns:
channel with given name, null if non-existant.

getChannels

public gov.aps.jca.Channel[] getChannels()
Specified by:
getChannels in class gov.aps.jca.Context
See Also:
Context.getChannels()

pendIO

public void pendIO(double timeout)
            throws gov.aps.jca.TimeoutException,
                   gov.aps.jca.CAException,
                   IllegalStateException
Specified by:
pendIO in class gov.aps.jca.Context
Throws:
gov.aps.jca.TimeoutException
gov.aps.jca.CAException
IllegalStateException
See Also:
Context.pendIO(double)

testIO

public boolean testIO()
               throws gov.aps.jca.CAException,
                      IllegalStateException
Specified by:
testIO in class gov.aps.jca.Context
Throws:
gov.aps.jca.CAException
IllegalStateException
See Also:
Context.testIO()

pendEvent

public void pendEvent(double timeout)
               throws gov.aps.jca.CAException,
                      IllegalStateException
Specified by:
pendEvent in class gov.aps.jca.Context
Throws:
gov.aps.jca.CAException
IllegalStateException
See Also:
Context.pendEvent(double)

poll

public void poll()
          throws gov.aps.jca.CAException,
                 IllegalStateException
Specified by:
poll in class gov.aps.jca.Context
Throws:
gov.aps.jca.CAException
IllegalStateException
See Also:
Context.poll()

flushIO

public void flushIO()
             throws gov.aps.jca.CAException,
                    IllegalStateException
Specified by:
flushIO in class gov.aps.jca.Context
Throws:
gov.aps.jca.CAException
IllegalStateException
See Also:
Context.flushIO()

attachCurrentThread

public void attachCurrentThread()
                         throws gov.aps.jca.CAException,
                                IllegalStateException
Specified by:
attachCurrentThread in class gov.aps.jca.Context
Throws:
gov.aps.jca.CAException
IllegalStateException
See Also:
Context.attachCurrentThread()

printInfo

public void printInfo(PrintStream out)
               throws IllegalStateException
Overrides:
printInfo in class gov.aps.jca.Context
Throws:
IllegalStateException
See Also:
Context.printInfo(java.io.PrintStream)

isInitialized

public boolean isInitialized()
Get initialization status.

Returns:
initialization status.

isDestroyed

public boolean isDestroyed()
Get destruction status.

Returns:
destruction status.

getAddressList

public String getAddressList()
Get search address list.

Returns:
get search address list.

isAutoAddressList

public boolean isAutoAddressList()
Get auto search-list flag.

Returns:
auto search-list flag.

getBeaconPeriod

public float getBeaconPeriod()
Get beacon period (in seconds).

Returns:
beacon period (in seconds).

getConnectionTimeout

public float getConnectionTimeout()
Get connection timeout (in seconds).

Returns:
connection timeout (in seconds).

getLogger

public Logger getLogger()
Get logger.

Specified by:
getLogger in interface LoggerProvider
Returns:
logger.

getMaxArrayBytes

public int getMaxArrayBytes()
Get max size of payload.

Returns:
max size of payload.

getRepeaterPort

public int getRepeaterPort()
Get repeater port.

Returns:
repeater port.

getServerPort

public int getServerPort()
Get server port.

Specified by:
getServerPort in interface CAContext
Returns:
server port.

getBroadcastPort

public int getBroadcastPort()
Get broadcast port.

Specified by:
getBroadcastPort in interface CAContext
Returns:
broadcast port.

getEventDispatcher

public final gov.aps.jca.event.EventDispatcher getEventDispatcher()
Get event dispatcher.

Returns:
event dispatcher.

getReactor

public Reactor getReactor()
Get context reactor.

Specified by:
getReactor in interface CAContext
Returns:
context reactor.

getBroadcastTransport

public BroadcastTransport getBroadcastTransport()
Broadcast transport.

Specified by:
getBroadcastTransport in interface CAContext
Returns:
broadcast transport.

getTransportRegistry

public CATransportRegistry getTransportRegistry()
Get CA transport (virtual circuit) registry.

Specified by:
getTransportRegistry in interface CAContext
Returns:
CA transport (virtual circuit) registry.

getTimer

public Timer getTimer()
Get timer.

Specified by:
getTimer in interface CAContext
Returns:
timer.

getChannelSearchManager

public ChannelSearchManager getChannelSearchManager()
Get channel search manager.

Returns:
channel search manager.

getCachedBufferAllocator

public CachedByteBufferAllocator getCachedBufferAllocator()
Get cached byte allocator.

Specified by:
getCachedBufferAllocator in interface CAContext
Returns:
cached byte allocator.

getLeaderFollowersThreadPool

public LeaderFollowersThreadPool getLeaderFollowersThreadPool()
Get LF thread pool.

Specified by:
getLeaderFollowersThreadPool in interface CAContext
Returns:
LF thread pool, can be null if disabled.

isRegistrationConfirmed

public boolean isRegistrationConfirmed()
Get repeater registration status.

Returns:
repeater registration status.

repeaterConfirm

public void repeaterConfirm(InetSocketAddress responseFrom)
Repeater registration confirmation.

Parameters:
responseFrom - response from address.

beaconAnomalyNotify

public void beaconAnomalyNotify()
Called each time beacon anomaly is detected.


searchResponse

public void searchResponse(int cid,
                           int sid,
                           short type,
                           int count,
                           short minorRevision,
                           InetSocketAddress serverAddress)
Search response from server (channel found).

Parameters:
cid - client channel ID.
sid - server channel ID.
type - channel type code.
count - channel element count.
minorRevision - server minor CA revision.
serverAddress - server address.

getResponseRequest

public ResponseRequest getResponseRequest(int ioid)
Searches for a response request with given channel IOID.

Parameters:
ioid - I/O ID.
Returns:
request response with given I/O ID.

registerResponseRequest

public int registerResponseRequest(ResponseRequest request)
Register response request.

Parameters:
request - request to register.
Returns:
request ID (IOID).

unregisterResponseRequest

public ResponseRequest unregisterResponseRequest(ResponseRequest request)
Unregister response request.

Parameters:
request -
Returns:
removed object, can be null

incrementPendingRequests

public int incrementPendingRequests()
Increment pending requests counter.

Returns:
IO sequence number (pendIO sequence number).

decrementPendingRequests

public void decrementPendingRequests(int usedSequenceNumberIO)
Decrement pending requests counter.

Parameters:
usedSequenceNumberIO - IO sequence number returned by incrementPendingRequests

setLastReceivedSequenceNumber

public final void setLastReceivedSequenceNumber(int seqNo)
Set last UDP recived sequence number.

Parameters:
seqNo - last UDP recived sequence number.

getLastReceivedSequenceNumber

public final int getLastReceivedSequenceNumber(int seqNo)
Set last UDP recived sequence number.

Parameters:
seqNo - last UDP recived sequence number.

invalidateLastReceivedSequence

public final void invalidateLastReceivedSequence()
Description copied from interface: CAContext
Invalidate last (UDP) received sequence.

Specified by:
invalidateLastReceivedSequence in interface CAContext
See Also:
CAContext.invalidateLastReceivedSequence()

getBeaconHandler

public CABeaconHandler getBeaconHandler(InetSocketAddress responseFrom)
Get (and if necessary create) beacon handler.

Parameters:
responseFrom - remote source address of received beacon.
Returns:
beacon handler for particular server.


Copyright © 2004-2013 Cosylab. All Rights Reserved.