Package org.openwebnet4j.communication
Class OpenConnector
- java.lang.Object
-
- org.openwebnet4j.communication.OpenConnector
-
- Direct Known Subclasses:
BUSConnector
,USBConnector
public abstract class OpenConnector extends Object
Abstract connector for communicating with an OpenWebNet gateway using command command (CMD) and monitoring (MON) connections- Author:
- M. Valla - Initial contribution
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
OpenConnector.OWNReceiveThread
OWNReceiveThread is a thread to read frames from MON InputStream
-
Field Summary
Fields Modifier and Type Field Description protected FrameChannel
cmdChannel
protected boolean
isCmdConnected
protected boolean
isMonConnected
protected long
lastCmdFrameSentTs
protected ConnectorListener
listener
protected FrameChannel
monChannel
protected OpenConnector.OWNReceiveThread
monRcvThread
protected ExecutorService
notifierExecutor
protected static int
OWN_MAX_DATA
-
Constructor Summary
Constructors Constructor Description OpenConnector()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
disconnect()
Disconnects both MON and CMD connections and stops MON receive threadprotected void
disconnectCmdChannel()
protected void
disconnectMonChannel()
long
getLastCmdFrameSentTs()
Get timestamp of last CMD frame sent successfullyprotected void
handleMonDisconnect(OWNException e)
Called when MON connection is disconnectedboolean
isCmdConnected()
Check if CMD is connectedboolean
isMonConnected()
Check if MON is connectedprotected void
notifyListener(OpenMessage msg)
Notify new message on MON connection to OpenListener using notifierExecutorabstract void
openCmdConn()
Opens command (CMD) connectionabstract void
openMonConn()
Opens monitor (MON) connectionprotected abstract void
processFrame(String newFrame)
Process a frame string receivedResponse
sendCommandSynch(String frame)
Send a command frame String on the connection, waits for aAckOpenMessage
(ACN/NACK) or timeout and returns the received messages in aResponse
objectprotected abstract Response
sendCommandSynchInternal(String frame)
void
setListener(ConnectorListener listener)
Sets theConnectorListener
for MONITOR events for this OpenConnector
-
-
-
Field Detail
-
OWN_MAX_DATA
protected static final int OWN_MAX_DATA
- See Also:
- Constant Field Values
-
cmdChannel
protected FrameChannel cmdChannel
-
monChannel
protected FrameChannel monChannel
-
isCmdConnected
protected boolean isCmdConnected
-
isMonConnected
protected boolean isMonConnected
-
lastCmdFrameSentTs
protected long lastCmdFrameSentTs
-
monRcvThread
protected OpenConnector.OWNReceiveThread monRcvThread
-
listener
protected ConnectorListener listener
-
notifierExecutor
protected ExecutorService notifierExecutor
-
-
Method Detail
-
openCmdConn
public abstract void openCmdConn() throws OWNException
Opens command (CMD) connection- Throws:
OWNException
- in case of error
-
openMonConn
public abstract void openMonConn() throws OWNException
Opens monitor (MON) connection- Throws:
OWNException
- in case of error
-
isCmdConnected
public boolean isCmdConnected()
Check if CMD is connected- Returns:
- boolean true if connected
-
getLastCmdFrameSentTs
public long getLastCmdFrameSentTs()
Get timestamp of last CMD frame sent successfully- Returns:
- long timestamp
-
isMonConnected
public boolean isMonConnected()
Check if MON is connected- Returns:
- boolean true if connected
-
setListener
public void setListener(ConnectorListener listener)
Sets theConnectorListener
for MONITOR events for this OpenConnector- Parameters:
listener
- the ConnectorListener to set
-
sendCommandSynch
public Response sendCommandSynch(String frame) throws OWNException
Send a command frame String on the connection, waits for aAckOpenMessage
(ACN/NACK) or timeout and returns the received messages in aResponse
object- Parameters:
frame
- the frame String to send- Returns:
Response
object with messages received as response- Throws:
OWNException
- in case of error while sending command frame or reading response
-
sendCommandSynchInternal
protected abstract Response sendCommandSynchInternal(String frame) throws IOException, FrameException
- Throws:
IOException
FrameException
-
processFrame
protected abstract void processFrame(String newFrame)
Process a frame string received- Parameters:
newFrame
- the new frame received
-
notifyListener
protected void notifyListener(OpenMessage msg)
Notify new message on MON connection to OpenListener using notifierExecutor- Parameters:
msg
- theOpenMessage
to be notified
-
handleMonDisconnect
protected void handleMonDisconnect(OWNException e)
Called when MON connection is disconnected- Parameters:
e
- the {link OWNException} received when disconnected
-
disconnect
public void disconnect()
Disconnects both MON and CMD connections and stops MON receive thread
-
disconnectMonChannel
protected void disconnectMonChannel()
-
disconnectCmdChannel
protected void disconnectCmdChannel()
-
-