com.cosylab.epics.caj.cas
Class CASTransport

java.lang.Object
  extended by com.cosylab.epics.caj.cas.CASTransport
All Implemented Interfaces:
ReactorHandler, Transport, Runnable

public class CASTransport
extends Object
implements Transport, ReactorHandler, Runnable

CAS transport implementation.

Version:
$id$
Author:
Matej Sekoranja

Field Summary
protected  ResponseHandler responseHandler
          CAS reponse handler.
 
Constructor Summary
CASTransport(CAContext context, SocketChannel channel)
           
 
Method Summary
 void close(boolean forced)
          Close connection.
 void depreallocateChannelSID(int sid)
          De-preallocate new channel SID.
 void eventsOff()
          Turn event dispatching off.
 void eventsOn()
          Turn event dispatching on.
 boolean flush()
          Flush send buffer.
 boolean flushInternal()
          Flush send buffer (blocks until flushed).
 gov.aps.jca.cas.ServerChannel getChannel(int sid)
          Get channel by its SID.
 gov.aps.jca.cas.ServerChannel getChannelAndVerifyRequest(int sid, short dataType, int dataCount)
          Get channel by its SID and do some additional checks.
 int getChannelCount()
          Get channel count.
 String getClientHostname()
          Get client hostname.
 String getClientUsername()
          Get client username.
 CAContext getContext()
          Get context transport is living in.
 short getMinorRevision()
          Transport protocol minor revision.
 short getPriority()
          Transport priority.
 InetSocketAddress getRemoteAddress()
          Get remote address.
 void handleEvent(SelectionKey key)
          Handle IO event.
 boolean hasReplaceEventPolicy()
          Get replace event policy flag.
 int preallocateChannelSID()
          Preallocate new channel SID.
 boolean processEvents(Runnable event)
          Process event.
protected  void processRead()
          Process input (read) IO event.
protected  void processWrite()
          Process output (write) IO event.
 void registerChannel(int sid, gov.aps.jca.cas.ServerChannel channel)
          Register a new channel.
 void run()
          Event dispatching is done here.
 void send(ByteBuffer buffer)
          Send a buffer through the transport.
 void setClientHostname(String clientHostname)
          Set client hostname.
 void setClientUsername(String clientUsername)
          Set client username.
 void setMinorRevision(short minorRevision)
          Set minor revision number.
 void setPriority(short priority)
          Set transport priority.
 void submit(Request requestMessage)
          Enqueue (if supported or if necessary send immediately) request message.
 void unregisterChannel(int sid)
          Unregister a new channel (and deallocates its handle).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

responseHandler

protected ResponseHandler responseHandler
CAS reponse handler.

Constructor Detail

CASTransport

public CASTransport(CAContext context,
                    SocketChannel channel)
Parameters:
context -
channel -
Method Detail

close

public void close(boolean forced)
Close connection.

Parameters:
forced - flag indicating if forced (e.g. forced disconnect) is required

getMinorRevision

public short getMinorRevision()
Description copied from interface: Transport
Transport protocol minor revision.

Specified by:
getMinorRevision in interface Transport
Returns:
protocol minor revision.
See Also:
Transport.getMinorRevision()

setMinorRevision

public void setMinorRevision(short minorRevision)
Set minor revision number.

Parameters:
minorRevision - minor revision number.

handleEvent

public void handleEvent(SelectionKey key)
Handle IO event.

Specified by:
handleEvent in interface ReactorHandler
Parameters:
key - key to be processed.
See Also:
ReactorHandler.handleEvent(java.nio.channels.SelectionKey)

processRead

protected void processRead()
Process input (read) IO event.


processWrite

protected void processWrite()
Process output (write) IO event.


send

public void send(ByteBuffer buffer)
          throws IOException
Send a buffer through the transport. NOTE: TCP sent buffer/sending has to be synchronized.

Parameters:
buffer - buffer to be sent
Throws:
IOException

flush

public boolean flush()
Flush send buffer. ... by enabling SelectionKey.OP_WRITE and process in reactor.

Specified by:
flush in interface Transport
Returns:
true on success, false on failure.
See Also:
Transport.flush()

flushInternal

public boolean flushInternal()
Flush send buffer (blocks until flushed).

Returns:
success flag.
See Also:
Transport.flush()

submit

public void submit(Request requestMessage)
            throws IOException
Description copied from interface: Transport
Enqueue (if supported or if necessary send immediately) request message. Message is sent immediately if its priority equals SEND_IMMEDIATELY_PRIORITY.

Specified by:
submit in interface Transport
Parameters:
requestMessage - request message to enqueue.
Throws:
IOException
See Also:
Transport.submit(com.cosylab.epics.caj.impl.Request)

getContext

public CAContext getContext()
Description copied from interface: Transport
Get context transport is living in.

Specified by:
getContext in interface Transport
Returns:
context transport is living in.
See Also:
Transport.getContext()

getRemoteAddress

public InetSocketAddress getRemoteAddress()
Description copied from interface: Transport
Get remote address.

Specified by:
getRemoteAddress in interface Transport
Returns:
remote address.
See Also:
Transport.getRemoteAddress()

getPriority

public short getPriority()
Description copied from interface: Transport
Transport priority.

Specified by:
getPriority in interface Transport
Returns:
protocol priority.
See Also:
Transport.getPriority()

setPriority

public void setPriority(short priority)
Set transport priority.


getClientHostname

public String getClientHostname()
Get client hostname.

Returns:
client hostname, null if unset.

getClientUsername

public String getClientUsername()
Get client username.

Returns:
client username, null if unset.

setClientHostname

public void setClientHostname(String clientHostname)
Set client hostname.

Parameters:
clientHostname - client hostname.

setClientUsername

public void setClientUsername(String clientUsername)
Set client username.

Parameters:
clientUsername - client username.

preallocateChannelSID

public int preallocateChannelSID()
Preallocate new channel SID.

Returns:
new channel server id (SID).

depreallocateChannelSID

public void depreallocateChannelSID(int sid)
De-preallocate new channel SID.

Parameters:
sid - preallocated channel SID.

registerChannel

public void registerChannel(int sid,
                            gov.aps.jca.cas.ServerChannel channel)
Register a new channel.

Parameters:
sid - preallocated channel SID.
channel - channel to register.

unregisterChannel

public void unregisterChannel(int sid)
Unregister a new channel (and deallocates its handle).

Parameters:
sid - SID

getChannel

public gov.aps.jca.cas.ServerChannel getChannel(int sid)
Get channel by its SID.

Parameters:
sid - channel SID
Returns:
channel with given SID, null otherwise

getChannelAndVerifyRequest

public gov.aps.jca.cas.ServerChannel getChannelAndVerifyRequest(int sid,
                                                                short dataType,
                                                                int dataCount)
                                                         throws gov.aps.jca.CAStatusException
Get channel by its SID and do some additional checks.

Parameters:
sid - channel SID
Returns:
channel with given SID, exception with status is thrown otherwise
Throws:
gov.aps.jca.CAStatusException

getChannelCount

public int getChannelCount()
Get channel count.

Returns:
channel count.

eventsOff

public void eventsOff()
Turn event dispatching off.


eventsOn

public void eventsOn()
Turn event dispatching on.


hasReplaceEventPolicy

public final boolean hasReplaceEventPolicy()
Get replace event policy flag.

Returns:
replace event policy flag.

processEvents

public boolean processEvents(Runnable event)
Process event.

Parameters:
event - event to be processed.
Returns:
success flag.

run

public void run()
Event dispatching is done here.

Specified by:
run in interface Runnable
See Also:
Runnable.run()


Copyright © 2004-2013 Cosylab. All Rights Reserved.