Class ChannelImpl
- java.lang.Object
-
- org.epics.pvaccess.client.impl.remote.ChannelImpl
-
- All Implemented Interfaces:
Channel
,SearchInstance
,Lockable
,TransportClient
,TransportSender
,org.epics.pvdata.misc.Timer.TimerCallback
,org.epics.pvdata.pv.Requester
public class ChannelImpl extends Object implements Channel, SearchInstance, TransportClient, TransportSender, org.epics.pvdata.misc.Timer.TimerCallback
Implementation of PVAJ JCAChannel
.- Version:
- $Id$
- Author:
- Matej Sekoranja
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.epics.pvaccess.client.Channel
Channel.ConnectionState
-
-
Field Summary
Fields Modifier and Type Field Description protected InetSocketAddress[]
addresses
List of fixed addresses, ifnull
name resolution will be used.protected boolean
allowCreation
Allow reconnection flag.static org.epics.pvdata.pv.Status
channelDestroyed
static org.epics.pvdata.pv.Status
channelDisconnected
protected int
channelID
Client channel ID.protected Channel.ConnectionState
connectionState
Connection status.protected ClientContextImpl
context
Context.protected String
name
Channel name.protected short
priority
Process priority.protected int
references
Reference counting.protected ChannelRequester
requester
Channel requester.protected Map<Integer,ResponseRequest>
responseRequests
List of all channel's pending requests (keys are subscription IDs).protected int
serverChannelID
Server channel ID.protected Transport
transport
Server transport.
-
Constructor Summary
Constructors Modifier Constructor Description protected
ChannelImpl(ClientContextImpl context, int channelID, String name, ChannelRequester requester, short priority, InetSocketAddress[] addresses)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
acquire()
Increment reference.void
callback()
void
cancel()
void
channelDestroyedOnServer()
Transport
checkAndGetTransport()
Checks if channel is in connected state and returns transport.Transport
checkDestroyedAndGetTransport()
Checks if channel is destroyed and returns transport,null
not connected.protected void
connect()
void
connectionCompleted(int sid)
Called when channel created succeeded on the server.void
createChannel(Transport transport)
Create a channel, i.e.ChannelArray
createChannelArray(ChannelArrayRequester channelArrayRequester, org.epics.pvdata.pv.PVStructure pvRequest)
Create a ChannelArray.void
createChannelFailed()
Create channel failed.ChannelGet
createChannelGet(ChannelGetRequester channelGetRequester, org.epics.pvdata.pv.PVStructure pvRequest)
Create a ChannelGet.ChannelProcess
createChannelProcess(ChannelProcessRequester channelProcessRequester, org.epics.pvdata.pv.PVStructure pvRequest)
Create a ChannelProcess.ChannelPut
createChannelPut(ChannelPutRequester channelPutRequester, org.epics.pvdata.pv.PVStructure pvRequest)
Create a ChannelPut.ChannelPutGet
createChannelPutGet(ChannelPutGetRequester channelPutGetRequester, org.epics.pvdata.pv.PVStructure pvRequest)
Create a ChannelPutGet.ChannelRPC
createChannelRPC(ChannelRPCRequester channelRPCRequester, org.epics.pvdata.pv.PVStructure pvRequest)
Create a ChannelRPC (Remote Procedure Call).org.epics.pvdata.monitor.Monitor
createMonitor(org.epics.pvdata.monitor.MonitorRequester monitorRequester, org.epics.pvdata.pv.PVStructure pvRequest)
Create a Monitor.void
destroy()
Destroy the channel.void
destroy(boolean force)
void
destroyChannel(boolean force)
Actual destroy method, to be calledCAJContext
.protected void
disconnect()
void
disconnect(boolean initiateSearch, boolean remoteDestroy)
Disconnected notification.AccessRights
getAccessRights(org.epics.pvdata.pv.PVField pvField)
Get the access rights for a field of a PVStructure created via a call to createPVStructure.int
getChannelID()
Get client channel ID.String
getChannelName()
Get the channel name.ChannelRequester
getChannelRequester()
Get the channel requester.Channel.ConnectionState
getConnectionState()
Returns the connection state of this channel.ClientContextImpl
getContext()
Get context.void
getField(GetFieldRequester requester, String subField)
Get a Field which describes the subField.short
getPriority()
Get process priority.ChannelProvider
getProvider()
Get the the channel provider of this channel.String
getRemoteAddress()
NOTE: synchronization guarantees thattransport
is non-null
andstate == CONNECTED
.String
getRequesterName()
int
getServerChannelID()
Get SID.Transport
getTransport()
Get transport used by this channel.AtomicInteger
getUserValue()
void
initiateSearch(boolean penalize)
Initiate search (connect) procedure.boolean
isConnected()
Is the channel connected?void
lock()
void
message(String message, org.epics.pvdata.pv.MessageType messageType)
void
registerResponseRequest(ResponseRequest responseRequest)
Register a response request.void
searchResponse(GUID guid, byte minorRevision, InetSocketAddress serverAddress)
Search response from server (channel found).void
send(ByteBuffer buffer, TransportSendControl control)
Called by transport.void
timeout()
void
timerStopped()
String
toString()
void
transportChanged()
Notification of network change (server restarted).void
transportClosed()
Notification of forcefully closed transport.void
transportResponsive(Transport transport)
Notification of responsive transport (e.g.void
transportUnresponsive()
Notification of unresponsive transport (e.g.void
unlock()
void
unregisterResponseRequest(ResponseRequest responseRequest)
-
-
-
Field Detail
-
channelID
protected final int channelID
Client channel ID.
-
name
protected final String name
Channel name.
-
context
protected final ClientContextImpl context
Context.
-
priority
protected final short priority
Process priority.
-
addresses
protected final InetSocketAddress[] addresses
List of fixed addresses, ifnull
name resolution will be used.
-
connectionState
protected Channel.ConnectionState connectionState
Connection status.
-
requester
protected final ChannelRequester requester
Channel requester.
-
responseRequests
protected final Map<Integer,ResponseRequest> responseRequests
List of all channel's pending requests (keys are subscription IDs).
-
allowCreation
protected boolean allowCreation
Allow reconnection flag.
-
references
protected int references
Reference counting. NOTE: synced onthis
.
-
transport
protected Transport transport
Server transport.
-
serverChannelID
protected int serverChannelID
Server channel ID.
-
channelDestroyed
public static final org.epics.pvdata.pv.Status channelDestroyed
-
channelDisconnected
public static final org.epics.pvdata.pv.Status channelDisconnected
-
-
Constructor Detail
-
ChannelImpl
protected ChannelImpl(ClientContextImpl context, int channelID, String name, ChannelRequester requester, short priority, InetSocketAddress[] addresses) throws PVAException
- Throws:
PVAException
-
-
Method Detail
-
createChannel
public void createChannel(Transport transport)
Create a channel, i.e. submit create channel request to the server. This method is called after search is complete.- Parameters:
transport
- on what transport to create channel.
-
cancel
public void cancel()
- See Also:
ResponseRequest.cancel()
-
timeout
public void timeout()
- See Also:
ResponseRequest.timeout()
-
createChannelFailed
public void createChannelFailed()
Create channel failed.
-
connectionCompleted
public void connectionCompleted(int sid) throws IllegalStateException
Called when channel created succeeded on the server.sid
might not be valid, this depends on protocol revision.- Parameters:
sid
- server-side channel ID.- Throws:
IllegalStateException
- when called in wrong state.
-
channelDestroyedOnServer
public void channelDestroyedOnServer()
-
destroy
public void destroy(boolean force) throws PVAException, IllegalStateException
- Parameters:
force
- force destruction regardless of reference count- Throws:
PVAException
- thrown on unexpected exception.IllegalStateException
- thrown if channel is already destroyed.
-
acquire
public void acquire()
Increment reference.
-
destroyChannel
public void destroyChannel(boolean force) throws PVAException, IllegalStateException, IOException
Actual destroy method, to be calledCAJContext
.- Parameters:
force
- force destruction regardless of reference count- Throws:
PVAException
- thrown on unexpected exception.IllegalStateException
- thrown when channel is destroyed.IOException
- thrown if IO exception occurs.
-
disconnect
public void disconnect(boolean initiateSearch, boolean remoteDestroy)
Disconnected notification.- Parameters:
initiateSearch
- flag to indicate if searching (connect) procedure should be initiatedremoteDestroy
- issue channel destroy request.
-
initiateSearch
public void initiateSearch(boolean penalize)
Initiate search (connect) procedure.- Parameters:
penalize
- register with penalty.
-
callback
public void callback()
- Specified by:
callback
in interfaceorg.epics.pvdata.misc.Timer.TimerCallback
-
timerStopped
public void timerStopped()
- Specified by:
timerStopped
in interfaceorg.epics.pvdata.misc.Timer.TimerCallback
-
getUserValue
public AtomicInteger getUserValue()
- Specified by:
getUserValue
in interfaceSearchInstance
-
searchResponse
public void searchResponse(GUID guid, byte minorRevision, InetSocketAddress serverAddress)
Description copied from interface:SearchInstance
Search response from server (channel found).- Specified by:
searchResponse
in interfaceSearchInstance
- Parameters:
guid
- server GUIDminorRevision
- server minor PVA revision.serverAddress
- server address.
-
transportClosed
public void transportClosed()
Description copied from interface:TransportClient
Notification of forcefully closed transport.- Specified by:
transportClosed
in interfaceTransportClient
- See Also:
TransportClient.transportClosed()
-
transportChanged
public void transportChanged()
Description copied from interface:TransportClient
Notification of network change (server restarted).- Specified by:
transportChanged
in interfaceTransportClient
- See Also:
TransportClient.transportChanged()
-
transportResponsive
public void transportResponsive(Transport transport)
Description copied from interface:TransportClient
Notification of responsive transport (e.g. heartbeat detected again), called to discardtransportUnresponsive
notification.- Specified by:
transportResponsive
in interfaceTransportClient
- Parameters:
transport
- responsive transport.- See Also:
TransportClient.transportResponsive(org.epics.pvaccess.impl.remote.Transport)
-
transportUnresponsive
public void transportUnresponsive()
Description copied from interface:TransportClient
Notification of unresponsive transport (e.g. no heartbeat detected) .- Specified by:
transportUnresponsive
in interfaceTransportClient
- See Also:
TransportClient.transportUnresponsive()
-
getConnectionState
public Channel.ConnectionState getConnectionState()
Description copied from interface:Channel
Returns the connection state of this channel.- Specified by:
getConnectionState
in interfaceChannel
- Returns:
- the
ConnectionState
value.
-
getRemoteAddress
public String getRemoteAddress()
NOTE: synchronization guarantees thattransport
is non-null
andstate == CONNECTED
.- Specified by:
getRemoteAddress
in interfaceChannel
- Returns:
- the channel's remote address.
- See Also:
Channel.getRemoteAddress()
-
getChannelID
public int getChannelID()
Get client channel ID.- Specified by:
getChannelID
in interfaceSearchInstance
- Returns:
- client channel ID.
-
getContext
public ClientContextImpl getContext()
Get context.- Returns:
- context.
-
checkAndGetTransport
public final Transport checkAndGetTransport()
Checks if channel is in connected state and returns transport.- Returns:
- used transport.
- Throws:
IllegalStateException
- if not connected.
-
checkDestroyedAndGetTransport
public final Transport checkDestroyedAndGetTransport()
Checks if channel is destroyed and returns transport,null
not connected.- Returns:
- used transport.
- Throws:
IllegalStateException
- if not connected
-
getTransport
public Transport getTransport()
Get transport used by this channel.- Returns:
- transport used by this channel.
-
getServerChannelID
public int getServerChannelID()
Get SID.- Returns:
- SID.
-
registerResponseRequest
public void registerResponseRequest(ResponseRequest responseRequest)
Register a response request.- Parameters:
responseRequest
- response request to register.
-
unregisterResponseRequest
public void unregisterResponseRequest(ResponseRequest responseRequest)
-
getPriority
public short getPriority()
Get process priority.- Returns:
- process priority.
-
connect
protected final void connect()
-
disconnect
protected void disconnect()
-
createChannelGet
public ChannelGet createChannelGet(ChannelGetRequester channelGetRequester, org.epics.pvdata.pv.PVStructure pvRequest)
Description copied from interface:Channel
Create a ChannelGet. ChannelGetRequester.channelGetReady is called after both client and server are ready for the client to make a get request.- Specified by:
createChannelGet
in interfaceChannel
- Parameters:
channelGetRequester
- The interface for notifying when this request is complete and when a channel get completes.pvRequest
- A structure describing the desired set of fields from the remote PVRecord. This has the same form as a pvRequest to PVCopyFactory.create.- Returns:
ChannelGet
instance.
-
createMonitor
public org.epics.pvdata.monitor.Monitor createMonitor(org.epics.pvdata.monitor.MonitorRequester monitorRequester, org.epics.pvdata.pv.PVStructure pvRequest)
Description copied from interface:Channel
Create a Monitor.- Specified by:
createMonitor
in interfaceChannel
- Parameters:
monitorRequester
- The requester.pvRequest
- A structure describing the desired set of fields from the remote PVRecord. This has the same form as a pvRequest to PVCopyFactory.create.- Returns:
Monitor
instance.
-
createChannelProcess
public ChannelProcess createChannelProcess(ChannelProcessRequester channelProcessRequester, org.epics.pvdata.pv.PVStructure pvRequest)
Description copied from interface:Channel
Create a ChannelProcess. ChannelProcessRequester.channelProcessReady is called after both client and server are ready for the client to make a process request.- Specified by:
createChannelProcess
in interfaceChannel
- Parameters:
channelProcessRequester
- The interface for notifying when this request is complete and when channel completes processing.pvRequest
- Additional options (e.g. triggering).- Returns:
ChannelProcess
instance.
-
createChannelPut
public ChannelPut createChannelPut(ChannelPutRequester channelPutRequester, org.epics.pvdata.pv.PVStructure pvRequest)
Description copied from interface:Channel
Create a ChannelPut. ChannelPutRequester.channelPutReady is called after both client and server are ready for the client to make a put request.- Specified by:
createChannelPut
in interfaceChannel
- Parameters:
channelPutRequester
- The interface for notifying when this request is complete and when a channel get completes.pvRequest
- A structure describing the desired set of fields from the remote PVRecord. This has the same form as a pvRequest to PVCopyFactory.create.- Returns:
ChannelPut
instance.
-
createChannelPutGet
public ChannelPutGet createChannelPutGet(ChannelPutGetRequester channelPutGetRequester, org.epics.pvdata.pv.PVStructure pvRequest)
Description copied from interface:Channel
Create a ChannelPutGet. ChannelPutGetRequester.channelPutGetReady is called after both client and server are ready for the client to make a putGet request.- Specified by:
createChannelPutGet
in interfaceChannel
- Parameters:
channelPutGetRequester
- The interface for notifying when this request is complete and when a channel get completes.pvRequest
- A structure describing the desired set of fields from the remote PVRecord. This has the same form as a pvRequest to PVCopyFactory.create.- Returns:
ChannelPutGet
instance.
-
createChannelRPC
public ChannelRPC createChannelRPC(ChannelRPCRequester channelRPCRequester, org.epics.pvdata.pv.PVStructure pvRequest)
Description copied from interface:Channel
Create a ChannelRPC (Remote Procedure Call).- Specified by:
createChannelRPC
in interfaceChannel
- Parameters:
channelRPCRequester
- The requester.pvRequest
- Request options.- Returns:
ChannelRPC
instance.
-
getAccessRights
public AccessRights getAccessRights(org.epics.pvdata.pv.PVField pvField)
Description copied from interface:Channel
Get the access rights for a field of a PVStructure created via a call to createPVStructure. MATEJ Channel access can store this info via auxInfo.- Specified by:
getAccessRights
in interfaceChannel
- Parameters:
pvField
- The field for which access rights is desired.- Returns:
- The access rights.
-
getChannelName
public String getChannelName()
Description copied from interface:Channel
Get the channel name.- Specified by:
getChannelName
in interfaceChannel
- Specified by:
getChannelName
in interfaceSearchInstance
- Returns:
- The name.
-
getChannelRequester
public ChannelRequester getChannelRequester()
Description copied from interface:Channel
Get the channel requester.- Specified by:
getChannelRequester
in interfaceChannel
- Returns:
- The requester.
-
getProvider
public ChannelProvider getProvider()
Description copied from interface:Channel
Get the the channel provider of this channel.- Specified by:
getProvider
in interfaceChannel
- Returns:
- The channel provider.
-
isConnected
public boolean isConnected()
Description copied from interface:Channel
Is the channel connected?- Specified by:
isConnected
in interfaceChannel
- Returns:
- (false,true) means (not, is) connected.
-
getRequesterName
public String getRequesterName()
- Specified by:
getRequesterName
in interfaceorg.epics.pvdata.pv.Requester
-
message
public void message(String message, org.epics.pvdata.pv.MessageType messageType)
- Specified by:
message
in interfaceorg.epics.pvdata.pv.Requester
-
destroy
public void destroy()
Description copied from interface:Channel
Destroy the channel. It will not honor any further requests.
-
createChannelArray
public ChannelArray createChannelArray(ChannelArrayRequester channelArrayRequester, org.epics.pvdata.pv.PVStructure pvRequest)
Description copied from interface:Channel
Create a ChannelArray.- Specified by:
createChannelArray
in interfaceChannel
- Parameters:
channelArrayRequester
- The ChannelArrayRequesterpvRequest
- Additional options (e.g. triggering).- Returns:
ChannelArray
instance.
-
getField
public void getField(GetFieldRequester requester, String subField)
Description copied from interface:Channel
Get a Field which describes the subField. GetFieldRequester.getDone is called after both client and server have processed the getField request. This is for clients that want to introspect a PVRecord via channel access.
-
send
public void send(ByteBuffer buffer, TransportSendControl control)
Description copied from interface:TransportSender
Called by transport. By this call transport gives callee ownership over the buffer. Calls onTransportSendControl
instance must be made from calling thread. Moreover, ownership is valid only for the time of call of this method. NOTE: these limitations allow efficient implementation.- Specified by:
send
in interfaceTransportSender
- Parameters:
buffer
- buffer to send.control
- transport send control instance.
-
-