Package com.cosylab.epics.caj.cas
Class CASTransport
- java.lang.Object
-
- 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
Fields Modifier and Type Field Description protected ResponseHandlerresponseHandlerCAS reponse handler.
-
Constructor Summary
Constructors Constructor Description CASTransport(CAContext context, SocketChannel channel)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose(boolean forced)Close connection.voiddepreallocateChannelSID(int sid)De-preallocate new channel SID.voideventsOff()Turn event dispatching off.voideventsOn()Turn event dispatching on.booleanflush()Flush send buffer.booleanflushInternal()Flush send buffer (blocks until flushed).ServerChannelgetChannel(int sid)Get channel by its SID.ServerChannelgetChannelAndVerifyRequest(int sid, short dataType, int dataCount)Get channel by its SID and do some additional checks.intgetChannelCount()Get channel count.StringgetClientHostname()Get client hostname.StringgetClientUsername()Get client username.CAContextgetContext()Get context transport is living in.shortgetMinorRevision()Transport protocol minor revision.shortgetPriority()Transport priority.InetSocketAddressgetRemoteAddress()Get remote address.voidhandleEvent(SelectionKey key)Handle IO event.booleanhasReplaceEventPolicy()Get replace event policy flag.intpreallocateChannelSID()Preallocate new channel SID.booleanprocessEvents(Runnable event)Process event.protected voidprocessRead()Process input (read) IO event.protected voidprocessWrite()Process output (write) IO event.voidregisterChannel(int sid, ServerChannel channel)Register a new channel.voidrun()Event dispatching is done here.voidsend(ByteBuffer buffer)Send a buffer through the transport.voidsetClientHostname(String clientHostname)Set client hostname.voidsetClientUsername(String clientUsername)Set client username.voidsetMinorRevision(short minorRevision)Set minor revision number.voidsetPriority(short priority)Set transport priority.voidsubmit(Request requestMessage)Enqueue (if supported or if necessary send immediately) request message.voidunregisterChannel(int sid)Unregister a new channel (and deallocates its handle).
-
-
-
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:TransportTransport protocol minor revision.- Specified by:
getMinorRevisionin interfaceTransport- 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:
handleEventin interfaceReactorHandler- 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:
flushin interfaceTransport- Returns:
trueon success,falseon 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:TransportEnqueue (if supported or if necessary send immediately) request message. Message is sent immediately if its priority equalsSEND_IMMEDIATELY_PRIORITY.- Specified by:
submitin interfaceTransport- 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:TransportGet context transport is living in.- Specified by:
getContextin interfaceTransport- Returns:
- context transport is living in.
- See Also:
Transport.getContext()
-
getRemoteAddress
public InetSocketAddress getRemoteAddress()
Description copied from interface:TransportGet remote address.- Specified by:
getRemoteAddressin interfaceTransport- Returns:
- remote address.
- See Also:
Transport.getRemoteAddress()
-
getPriority
public short getPriority()
Description copied from interface:TransportTransport priority.- Specified by:
getPriorityin interfaceTransport- 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,
nullif unset.
-
getClientUsername
public String getClientUsername()
Get client username.- Returns:
- client username,
nullif 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, 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 ServerChannel getChannel(int sid)
Get channel by its SID.- Parameters:
sid- channel SID- Returns:
- channel with given SID,
nullotherwise
-
getChannelAndVerifyRequest
public ServerChannel getChannelAndVerifyRequest(int sid, short dataType, int dataCount) throws 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:
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:
runin interfaceRunnable- See Also:
Runnable.run()
-
-