Package org.openmuc.jship.api
Class Ship
- java.lang.Object
-
- org.openmuc.jship.api.Ship
-
- All Implemented Interfaces:
ShipInterface
public class Ship extends java.lang.Object implements ShipInterface
-
-
Constructor Summary
Constructors Constructor Description Ship(java.lang.String alias, ShipNodeConfiguration nodeConfig, ConnectionHandler connHandler)
constructor with parameters for convenience
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTrustedSki(java.lang.String ski)
adding a SKI authenticates the SHIP node using that SKI.void
createServer(int port, java.lang.String wssPath, boolean keepAlive)
static javax.jmdns.ServiceInfo
createServiceInfo(java.lang.String serviceName, java.lang.String serviceInstance, int port, TxtRecord txt)
static TxtRecord
createTxtRecord(java.lang.String id, java.lang.String path, java.lang.String ski, boolean register)
static TxtRecord
createTxtRecord(java.lang.String id, java.lang.String path, java.lang.String ski, boolean register, java.lang.String brand, java.lang.String type, java.lang.String model)
java.lang.String
getOwnSki()
javax.jmdns.ServiceInfo[]
getServices()
returns an array with all detected services, including own serviceShipConnectionInterface
openConnection(java.lang.String ipAddr)
opens a connection to a device/serverboolean
removeTrustedSki(java.lang.String ski)
tries to remove a ski from the trusted SKIsvoid
runConnectionDataPreparation(ShipConnection connection)
run the states in connection data preparation, this method is non-blocking and the states will run asynchronouslyvoid
setAutoAcceptMode()
sets the node to auto-accept-mode.void
setClientConnectedCB(ClientConnectedCallBack clientConnectedCB)
void
setConnHandler(ConnectionHandler connHandler)
sets a connection handlervoid
shutDown()
shuts down service discovery, all servers and clients on the node and the node itself
-
-
-
Constructor Detail
-
Ship
public Ship(java.lang.String alias, ShipNodeConfiguration nodeConfig, ConnectionHandler connHandler)
constructor with parameters for convenience- Parameters:
alias
- alias for the key pair in key storeconnHandler
- connection handler
-
-
Method Detail
-
createTxtRecord
public static TxtRecord createTxtRecord(java.lang.String id, java.lang.String path, java.lang.String ski, boolean register)
-
createTxtRecord
public static TxtRecord createTxtRecord(java.lang.String id, java.lang.String path, java.lang.String ski, boolean register, java.lang.String brand, java.lang.String type, java.lang.String model)
-
createServiceInfo
public static javax.jmdns.ServiceInfo createServiceInfo(java.lang.String serviceName, java.lang.String serviceInstance, int port, TxtRecord txt)
-
createServer
public void createServer(int port, java.lang.String wssPath, boolean keepAlive)
-
openConnection
public ShipConnectionInterface openConnection(java.lang.String ipAddr)
opens a connection to a device/server- Specified by:
openConnection
in interfaceShipInterface
- Parameters:
ipAddr
- the IP address of the device/server to connect to. Example: "127.0.0.1:4059"- Returns:
- an object representing the connection to the device/server if the connection was successful, else
null
-
runConnectionDataPreparation
public void runConnectionDataPreparation(ShipConnection connection)
run the states in connection data preparation, this method is non-blocking and the states will run asynchronously- Parameters:
connection
- the connection that should run the connection data preparation states
-
getOwnSki
public java.lang.String getOwnSki()
-
addTrustedSki
public void addTrustedSki(java.lang.String ski)
adding a SKI authenticates the SHIP node using that SKI. The SKI of other SHIP nodes is typically communicated through theConnectionHandler
or manually acquired throughShipConnectionInterface
- Parameters:
ski
- the ski to add to the trusted SKIs
-
removeTrustedSki
public boolean removeTrustedSki(java.lang.String ski)
tries to remove a ski from the trusted SKIs- Parameters:
ski
- the ski to remove- Returns:
true
if the ski was removed successfully, otherwisefalse
, for example because the trusted SKI list did not contain the passed ski
-
setAutoAcceptMode
public void setAutoAcceptMode()
sets the node to auto-accept-mode. Authentication can be skipped that way but client has a time window for the connection, which can a preset value from 0 to 120 seconds. The default value for the window is 60 seconds. If the time window passed without any client connecting, the auto-accept-mode will be turned off.
-
setConnHandler
public void setConnHandler(ConnectionHandler connHandler)
Description copied from interface:ShipInterface
sets a connection handler- Specified by:
setConnHandler
in interfaceShipInterface
-
setClientConnectedCB
public void setClientConnectedCB(ClientConnectedCallBack clientConnectedCB)
-
getServices
public javax.jmdns.ServiceInfo[] getServices()
returns an array with all detected services, including own service- Returns:
- the array with all detected services
-
shutDown
public void shutDown() throws java.io.IOException
shuts down service discovery, all servers and clients on the node and the node itself- Throws:
java.io.IOException
- if service discovery shutdown unsuccessful
-
-