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 classOpenConnector.OWNReceiveThreadOWNReceiveThread is a thread to read frames from MON InputStream 
- 
Field Summary
Fields Modifier and Type Field Description protected FrameChannelcmdChannelprotected booleanisCmdConnectedprotected booleanisMonConnectedprotected longlastCmdFrameSentTsprotected ConnectorListenerlistenerprotected FrameChannelmonChannelprotected OpenConnector.OWNReceiveThreadmonRcvThreadprotected ExecutorServicenotifierExecutorprotected static intOWN_MAX_DATA 
- 
Constructor Summary
Constructors Constructor Description OpenConnector() 
- 
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voiddisconnect()Disconnects both MON and CMD connections and stops MON receive threadprotected voiddisconnectCmdChannel()protected voiddisconnectMonChannel()longgetLastCmdFrameSentTs()Get timestamp of last CMD frame sent successfullyprotected voidhandleMonDisconnect(OWNException e)Called when MON connection is disconnectedbooleanisCmdConnected()Check if CMD is connectedbooleanisMonConnected()Check if MON is connectedprotected voidnotifyListener(OpenMessage msg)Notify new message on MON connection to OpenListener using notifierExecutorabstract voidopenCmdConn()Opens command (CMD) connectionabstract voidopenMonConn()Opens monitor (MON) connectionprotected abstract voidprocessFrame(String newFrame)Process a frame string receivedResponsesendCommandSynch(String frame)Send a command frame String on the connection, waits for aAckOpenMessage(ACN/NACK) or timeout and returns the received messages in aResponseobjectprotected abstract ResponsesendCommandSynchInternal(String frame)voidsetListener(ConnectorListener listener)Sets theConnectorListenerfor 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 OWNExceptionOpens command (CMD) connection- Throws:
 OWNException- in case of error
 
- 
openMonConn
public abstract void openMonConn() throws OWNExceptionOpens 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 theConnectorListenerfor 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 aResponseobject- Parameters:
 frame- the frame String to send- Returns:
 Responseobject 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:
 IOExceptionFrameException
 
- 
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- theOpenMessageto 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()
 
 - 
 
 -