Skip to content

Commit

Permalink
further parameters checks; exceptions to logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Biasuzzi committed Oct 24, 2016
1 parent 6df9c0a commit a286934
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,13 @@
import eu.itesla_project.commons.config.PlatformConfig;

import java.io.Serializable;
import java.util.Objects;

/**
* @author Quinary <itesla@quinary.com>
*/
public class OnlineWorkflowStartParameters implements Serializable {

/*
* example of online-start-parameters.properties file.
*
# number of thread
threads=20
# JMX host and port
jmxHost=127.0.0.1
jmxPort=6667
#listenerFactoryClasses=eu.itesla_project.apogee_client.ApogeeOnlineApplicationListenerFactory
#onlineWorkflowFactoryClass=eu.itesla_project.quinary_utils.online.OnlineWorkFlowFactory
*/

private static final long serialVersionUID = 1L;
public static final int DEFAULT_THREADS = 1;

Expand All @@ -42,28 +29,21 @@ public class OnlineWorkflowStartParameters implements Serializable {
public static OnlineWorkflowStartParameters loadDefault() {
ModuleConfig config = PlatformConfig.defaultConfig().getModuleConfig("online-start-parameters");
int threads = config.getIntProperty("threads", DEFAULT_THREADS);
if (threads <= 0) {
threads = DEFAULT_THREADS;
}
String jmxHost = config.getStringProperty("jmxHost");
int jmxPort = config.getIntProperty("jmxPort");

Class<? extends OnlineWorkflowFactory> onlineWorkflowFactory = config.getClassProperty("onlineWorkflowFactoryClass", OnlineWorkflowFactory.class, OnlineWorkflowFactoryImpl.class);
String listenerFactoryClassName = config.getStringProperty("listenerFactoryClasses", null);
if (listenerFactoryClassName != null) {
Class<? extends OnlineApplicationListenerFactory> listenerFactoryClass = config.getClassProperty("listenerFactoryClasses", OnlineApplicationListenerFactory.class);
return new OnlineWorkflowStartParameters(threads, jmxHost, jmxPort, listenerFactoryClass, onlineWorkflowFactory);
}
Class<? extends OnlineApplicationListenerFactory> listenerFactoryClass = config.getClassProperty("listenerFactoryClasses", OnlineApplicationListenerFactory.class, null);

return new OnlineWorkflowStartParameters(threads, jmxHost, jmxPort, null, onlineWorkflowFactory);
return new OnlineWorkflowStartParameters(threads, jmxHost, jmxPort, listenerFactoryClass, onlineWorkflowFactory);
}

public OnlineWorkflowStartParameters(int threads, String jmxHost, int jmxPort, Class<? extends OnlineApplicationListenerFactory> listenerFactoryClass, Class<? extends OnlineWorkflowFactory> onlineWorkflowFactory) {
this.threads = threads;
this.jmxHost = jmxHost;
this.jmxPort = jmxPort;
this.listenerFactoryClasses = listenerFactoryClass;
Objects.requireNonNull(onlineWorkflowFactory);
this.onlineWorkflowFactory = onlineWorkflowFactory;
this.listenerFactoryClasses = listenerFactoryClass;
setJmxHost(jmxHost);
setJmxPort(jmxPort);
setThreads(threads);
}

public int getThreads() {
Expand All @@ -86,14 +66,21 @@ public String toString() {
}

public void setThreads(int threads) {
if (threads <= 0) {
throw new IllegalArgumentException("threads must be greater than zero: " + threads);
}
this.threads = threads;
}

public void setJmxHost(String jmxHost) {
Objects.requireNonNull(jmxHost);
this.jmxHost = jmxHost;
}

public void setJmxPort(int jmxPort) {
if (jmxPort <= 0) {
throw new IllegalArgumentException("jmxPort must be greater than zero: " + jmxPort);
}
this.jmxPort = jmxPort;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package eu.itesla_project.online;

import eu.itesla_project.modules.online.OnlineWorkflowParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.management.*;
import javax.management.remote.JMXConnector;
Expand All @@ -23,6 +25,8 @@
*/
public class RemoteOnlineApplication implements OnlineApplication, NotificationListener {

private static final Logger LOGGER = LoggerFactory.getLogger(RemoteOnlineApplication.class);

private final List<OnlineApplicationListener> listeners = new CopyOnWriteArrayList<>();

private JMXConnector connector;
Expand Down Expand Up @@ -73,8 +77,7 @@ private void connect() throws IOException, MalformedObjectNameException, Instanc
l.onConnection();
}
} catch (Exception ex) {
//ex.printStackTrace();
System.out.println("Exception connecting JMX " + ex);
LOGGER.error("Exception connecting JMX to "+ serviceURL + ": " + ex.getMessage(), ex);
}
}

Expand Down Expand Up @@ -172,7 +175,7 @@ public int getAvailableCores() {
try {
cores = application.getAvailableCores();
} catch (JMRuntimeException e) {
e.printStackTrace();
LOGGER.error(e.getMessage(),e);
notifyDisconnection();
}
return cores;
Expand All @@ -183,26 +186,22 @@ public int getAvailableCores() {
public void startWorkflow(OnlineWorkflowStartParameters start, OnlineWorkflowParameters params) {
try {
application.startWorkflow(start, params);

} catch (Exception e) {
e.printStackTrace();
LOGGER.error(e.getMessage(),e);
notifyDisconnection();
}
}

@Override
public void stopWorkflow() {

try {
application.stopWorkflow();
} catch (Exception e) {
e.printStackTrace();
LOGGER.error(e.getMessage(),e);
notifyDisconnection();
}

}


@Override
public void notifyListeners() {
application.notifyListeners();
Expand Down

0 comments on commit a286934

Please sign in to comment.