Package org.hcjf.io.net
Class NetService
- java.lang.Object
-
- org.hcjf.service.Service<NetServiceConsumer>
-
- org.hcjf.io.net.NetService
-
public final class NetService extends Service<NetServiceConsumer>
This class implements a service that provide an up-level interface to open tcp and udp connections like a server side or client side.- Author:
- javaito
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classNetService.NetIOThreadNet IO thread.static classNetService.TransportLayerProtocolTransport layer protocols.-
Nested classes/interfaces inherited from class org.hcjf.service.Service
Service.RunnableWrapperComparator, Service.ShutdownStage, Service.StaticServiceThread, Service.ThreadPoolAgent, Service.ThreadPoolAgentMBean
-
-
Field Summary
-
Fields inherited from class org.hcjf.service.Service
SERVICE_LOG_TAG
-
-
Method Summary
Modifier and Type Method Description booleancheckSession(NetSession session)Check if the specific session is active into the sercie.voiddisconnect(NetSession session, java.lang.String message)Disconnect a specific session.static NetServicegetInstance()Return the unique instance of the service.protected voidinit()This method will be called immediately after of the execution of the service's constructor methodbooleanisConnected(NetSession session)Indicates if the session is connected or notbooleanisShuttingDown()Return a boolean to knows if the instance of the java vm is into the shutdown process or not.voidregisterConsumer(NetServiceConsumer consumer)This method register the consumer in the service.protected voidshutdown(Service.ShutdownStage stage)This method will be called immediately after the static method 'shutdown' of the class has been called.voidunregisterConsumer(NetServiceConsumer consumer)Unregister a specific consumer.NetPackagewriteData(NetSession session, byte[] data)This method put a net package on the output queue of the session.-
Methods inherited from class org.hcjf.service.Service
call, call, fork, fork, fork, fork, getPriority, getServiceName, run, run, shutdownExecutor, systemShutdown
-
-
-
-
Method Detail
-
getInstance
public static final NetService getInstance()
Return the unique instance of the service.- Returns:
- Instance of the service.
-
init
protected void init()
This method will be called immediately after of the execution of the service's constructor method- Overrides:
initin classService<NetServiceConsumer>
-
shutdown
protected void shutdown(Service.ShutdownStage stage)
This method will be called immediately after the static method 'shutdown' of the class has been called.- Overrides:
shutdownin classService<NetServiceConsumer>- Parameters:
stage- Shutdown stage.
-
registerConsumer
public final void registerConsumer(NetServiceConsumer consumer)
This method register the consumer in the service.- Specified by:
registerConsumerin classService<NetServiceConsumer>- Parameters:
consumer- Consumer.- Throws:
java.lang.NullPointerException- If the consumer is null.java.lang.IllegalArgumentException- If the consumer is not a NetClient instance of a NetServer instance.java.lang.RuntimeException- With a IOException like a cause.
-
unregisterConsumer
public void unregisterConsumer(NetServiceConsumer consumer)
Description copied from class:ServiceUnregister a specific consumer.- Specified by:
unregisterConsumerin classService<NetServiceConsumer>- Parameters:
consumer- Consumer to unregister.
-
isShuttingDown
public final boolean isShuttingDown()
Return a boolean to knows if the instance of the java vm is into the shutdown process or not.- Returns:
- True if the vm is into the shutdown porcess and false in the otherwise.
-
checkSession
public final boolean checkSession(NetSession session)
Check if the specific session is active into the sercie.- Parameters:
session- Specific session.- Returns:
- Return true if the session is active into the
-
writeData
public final NetPackage writeData(NetSession session, byte[] data) throws java.io.IOException
This method put a net package on the output queue of the session.- Parameters:
session- Net session.data- Data to create the package.- Returns:
- Return the id of the created package.
- Throws:
java.io.IOException- Exception of the write operation.
-
disconnect
public final void disconnect(NetSession session, java.lang.String message)
Disconnect a specific session.- Parameters:
session- Session to disconnect.message- Disconnection message.
-
isConnected
public final boolean isConnected(NetSession session)
Indicates if the session is connected or not- Parameters:
session- Session- Returns:
- Return true if the session is connected and false in the other case.
-
-