use of jp.ossc.nimbus.daemon.Daemon in project nimbus by nimbus-org.
the class ClientConnectionImpl method connect.
private synchronized void connect(Object id, boolean isReconnect) throws ConnectException {
if (socket != null) {
return;
}
isConnected = false;
try {
try {
if (socketFactory == null) {
socket = new Socket(address, port, getBindAddress(), getBindPort());
} else {
socket = socketFactory.createSocket(address, port, getBindAddress(), getBindPort());
}
if (responseTimeout > 0) {
socket.setSoTimeout((int) responseTimeout);
}
if (!isReconnect) {
if (receiveAddress != null) {
receiveGroup = InetAddress.getByName(receiveAddress);
InetAddress bindAddress = getUDPBindAddress();
if (bindAddress == null) {
receiveSocket = receiveGroup.isMulticastAddress() ? new MulticastSocket(receivePort) : new DatagramSocket(receivePort);
} else {
final InetSocketAddress address = new InetSocketAddress(bindAddress, receivePort);
receiveSocket = receiveGroup.isMulticastAddress() ? new MulticastSocket(address) : new DatagramSocket(address);
}
if (receiveGroup.isMulticastAddress()) {
NetworkInterface[] networkInterfaces = getNetworkInterfaces();
if (networkInterfaces == null) {
((MulticastSocket) receiveSocket).joinGroup(receiveGroup);
} else {
for (int i = 0; i < networkInterfaces.length; i++) {
((MulticastSocket) receiveSocket).joinGroup(new InetSocketAddress(receiveGroup, receivePort), networkInterfaces[i]);
}
}
}
} else {
InetAddress bindAddress = getUDPBindAddress();
if (bindAddress == null) {
receiveSocket = new DatagramSocket(receivePort);
} else {
receiveSocket = new DatagramSocket(new InetSocketAddress(bindAddress, receivePort));
}
}
if (receivePort == 0) {
receivePortReal = receiveSocket.getLocalPort();
} else {
receivePortReal = receivePort;
}
if (receiveSocket != null) {
try {
int receiveBufferSize = receiveSocket.getReceiveBufferSize();
if (receiveBufferSize < windowSize) {
receiveSocket.setReceiveBufferSize(windowSize);
}
} catch (SocketException e) {
}
}
}
} catch (UnknownHostException e) {
throw new ConnectException(e);
} catch (NumberFormatException e) {
throw new ConnectException(e);
} catch (IOException e) {
throw new ConnectException(e);
}
if (receivePacketQueue == null) {
receivePacketQueue = new DefaultQueueService();
try {
receivePacketQueue.create();
receivePacketQueue.start();
} catch (Exception e) {
throw new ConnectException(e);
}
}
if (packetReceiveDaemon == null) {
packetReceiveDaemon = new Daemon(new PacketReceiver());
packetReceiveDaemon.setDaemon(true);
packetReceiveDaemon.setName("Nimbus Publish(UDP) ClientConnection PacketReceiver " + socket.getLocalSocketAddress());
packetReceiveDaemon.start();
}
if (replyReceiveDaemon == null) {
replyReceiveDaemon = new Daemon(new ReplyReceiver());
replyReceiveDaemon.setDaemon(true);
replyReceiveDaemon.setName("Nimbus Publish(UDP) ClientConnection ReplyReceiver " + socket.getLocalSocketAddress());
replyReceiveDaemon.start();
}
if (messageReceiveDaemon == null) {
messageReceiveDaemon = new Daemon(new MessageReceiver());
messageReceiveDaemon.setDaemon(true);
messageReceiveDaemon.setName("Nimbus Publish(UDP) ClientConnection MessageReceiver " + socket.getLocalSocketAddress());
}
if (missingWindowCheckDaemon == null) {
missingWindowCheckDaemon = new Daemon(new MissingWindowChecker((MessageReceiver) messageReceiveDaemon.getDaemonRunnable()));
missingWindowCheckDaemon.setDaemon(true);
missingWindowCheckDaemon.setName("Nimbus Publish(UDP) ClientConnection MissingWindowChecker " + socket.getLocalSocketAddress());
((MessageReceiver) messageReceiveDaemon.getDaemonRunnable()).setPacketReceiver((PacketReceiver) packetReceiveDaemon.getDaemonRunnable());
((MessageReceiver) messageReceiveDaemon.getDaemonRunnable()).setMissingWindowChecker((MissingWindowChecker) missingWindowCheckDaemon.getDaemonRunnable());
}
messageReceiveDaemon.start();
missingWindowCheckDaemon.start();
this.id = id == null ? socket.getLocalSocketAddress() : id;
try {
IdMessage message = new IdMessage(this.id);
message.setReceivePort(receivePortReal);
send(message, isAcknowledge);
} catch (IOException e) {
throw new ConnectException(e);
} catch (ClassNotFoundException e) {
throw new ConnectException(e);
}
if (serverServiceName != null) {
ServiceManager manager = ServiceManagerFactory.findManager(serviceManagerName == null ? serverServiceName.getServiceManagerName() : serviceManagerName);
if (manager != null) {
final ClientConnectionService ccs = new ClientConnectionService();
try {
String name = serverServiceName.getServiceName() + '$' + socket.getLocalSocketAddress();
name = name.replaceAll(":", "\\$");
if (!manager.isRegisteredService(name) && manager.registerService(name, ccs)) {
serviceName = ccs.getServiceNameObject();
manager.createService(ccs.getServiceName());
manager.startService(ccs.getServiceName());
}
} catch (Exception e) {
throw new ConnectException(e);
}
}
}
} catch (ConnectException e) {
if (socket != null) {
try {
socket.close();
} catch (IOException e2) {
}
socket = null;
}
if (!isReconnect && receiveSocket != null) {
receiveSocket.close();
receiveSocket = null;
}
throw e;
}
isConnected = true;
isServerClosed = false;
}
use of jp.ossc.nimbus.daemon.Daemon in project nimbus by nimbus-org.
the class MBeanWatcherService method startService.
public void startService() throws Exception {
if (jndiFinderServiceName != null) {
jndiFinder = (JndiFinder) ServiceManagerFactory.getServiceObject(jndiFinderServiceName);
} else if (serviceURL != null) {
if (isConnectOnStart) {
connector = JMXConnectorFactory.newJMXConnector(new JMXServiceURL(serviceURL), jmxConnectorEnvironment);
connector.connect();
}
/*
}else{
throw new IllegalArgumentException("ServiceURL or jndiFinderServiceName must be specified.");
*/
}
if (categoryServiceName != null) {
category = (Category) ServiceManagerFactory.getServiceObject(categoryServiceName);
}
for (int i = 0, imax = targetList.size(); i < imax; i++) {
Target target = (Target) targetList.get(i);
target.setWatcherServiceName(getServiceNameObject());
target.setWatcherService(this);
target.setLogger(getLogger());
if (isResetOnStart) {
target.reset();
}
target.start();
}
if (interval > 0) {
watcher = new Daemon(this);
watcher.setName("Nimbus MBeanWatcher " + getServiceNameObject());
watcher.setDaemon(true);
if (connector != null) {
JMXConnectorNotificationListener listener = new JMXConnectorNotificationListener();
connector.addConnectionNotificationListener(listener, listener, watcher);
}
watcher.start();
}
}
use of jp.ossc.nimbus.daemon.Daemon in project nimbus by nimbus-org.
the class ClientConnectionImpl method connect.
public synchronized void connect(Object id) throws ConnectException {
if (socket != null) {
return;
}
isConnected = false;
InetAddress bindAddress = null;
int bindPort = 0;
try {
bindAddress = getBindAddress();
bindPort = getBindPort();
if (socketFactory == null) {
socket = new Socket(address, port, bindAddress, bindPort);
} else {
socket = socketFactory.createSocket(address, port, bindAddress, bindPort);
}
} catch (UnknownHostException e) {
throw new ConnectException("address=" + address + ", port=" + port + ", bindAddress=" + bindAddress + ", bindPort=" + bindPort, e);
} catch (NumberFormatException e) {
throw new ConnectException(e);
} catch (IOException e) {
throw new ConnectException("address=" + address + ", port=" + port + ", bindAddress=" + bindAddress + ", bindPort=" + bindPort, e);
}
try {
if (messageReceiveDaemon == null) {
messageReceiveDaemon = new Daemon(this);
messageReceiveDaemon.setDaemon(true);
messageReceiveDaemon.setName("Nimbus Publish(TCP) ClientConnection SocketReader " + socket.getLocalSocketAddress());
messageReceiveDaemon.start();
}
this.id = id == null ? socket.getLocalSocketAddress() : id;
try {
send(new IdMessage(this.id));
} catch (IOException e) {
throw new ConnectException(e);
} catch (MessageSendException e) {
throw new ConnectException(e);
}
if (serviceManagerName != null && serverServiceName != null) {
ServiceManager manager = ServiceManagerFactory.findManager(serviceManagerName);
if (manager != null) {
final ClientConnectionService ccs = new ClientConnectionService();
try {
String name = serverServiceName.getServiceName() + '$' + socket.getLocalSocketAddress();
name = name.replaceAll(":", "\\$");
if (!manager.isRegisteredService(name) && manager.registerService(name, ccs)) {
serviceName = ccs.getServiceNameObject();
manager.createService(ccs.getServiceName());
manager.startService(ccs.getServiceName());
}
} catch (Exception e) {
throw new ConnectException(e);
}
}
}
} catch (ConnectException e) {
if (socket != null) {
try {
socket.close();
} catch (IOException e2) {
}
socket = null;
}
throw e;
}
isConnected = true;
isServerClosed = false;
}
use of jp.ossc.nimbus.daemon.Daemon in project nimbus by nimbus-org.
the class WsServiceMetricsHandlerService method startService.
/**
* サービスの開始処理を行う。<p>
*
* @exception Exception 開始処理に失敗した場合
*/
public void startService() throws Exception {
metricsInfos.clear();
if (keyAndCategoryServiceNameMapping != null && keyAndCategoryServiceNameMapping.size() != 0) {
final ServiceNameEditor nameEditor = new ServiceNameEditor();
nameEditor.setServiceManagerName(getServiceManagerName());
final Iterator keys = keyAndCategoryServiceNameMapping.keySet().iterator();
while (keys.hasNext()) {
final String key = (String) keys.next();
final String nameStr = keyAndCategoryServiceNameMapping.getProperty(key);
nameEditor.setAsText(nameStr);
final ServiceName name = (ServiceName) nameEditor.getValue();
final Category category = (Category) ServiceManagerFactory.getServiceObject(name);
keyAndCategoryMap.put(key, category);
}
}
if (categoryServiceName != null) {
metricsCategory = (Category) ServiceManagerFactory.getServiceObject(categoryServiceName);
}
if ((keyAndCategoryMap != null && keyAndCategoryMap.size() != 0) || metricsCategory != null) {
writerDaemon = new Daemon(this);
writerDaemon.setName("Nimbus MetricsWriteDaemon " + getServiceNameObject());
writerDaemon.start();
}
}
use of jp.ossc.nimbus.daemon.Daemon in project nimbus by nimbus-org.
the class DefaultPerformanceRecorderService method startService.
public void startService() throws Exception {
if (categoryServiceName != null) {
category = (Category) ServiceManagerFactory.getServiceObject(categoryServiceName);
}
threadLocal = new ThreadLocal() {
protected Object initialValue() {
Performance performance = new Performance();
synchronized (performanceSet) {
performanceSet.add(performance);
if (maxThread > 0 && performanceSet.size() > maxThread) {
Iterator itr = performanceSet.iterator();
itr.next();
itr.remove();
}
}
return performance;
}
};
resetDaemon = new Daemon(new ResetDaemonRunnable());
resetDaemon.setName("Nimbus PerformanceRecorderWriter " + getServiceNameObject());
resetDaemon.start();
}
Aggregations