Skip to content

Commit

Permalink
Merge pull request #21 from rwth-acis/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
derjasper authored Nov 4, 2016
2 parents a5b4a5b + 4ac9e51 commit d9ee916
Show file tree
Hide file tree
Showing 9 changed files with 331 additions and 111 deletions.
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<property name="ivy.organisation" value="i5" />
<property name="ivy.module" value="las2peer" />
<property name="ivy.revision" value="0.6" />
<property name="ivy.build.number" value="1" />
<property name="ivy.build.number" value="2" />
<property name="ivy.deliver.revision" value="${ivy.revision}" />
<property name="ivy.pom.version" value="${ivy.revision}" />

Expand Down
15 changes: 15 additions & 0 deletions src/main/java/i5/las2peer/p2p/AliasConflictException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package i5.las2peer.p2p;

public class AliasConflictException extends Exception {

private static final long serialVersionUID = 1L;

public AliasConflictException(String message) {
super(message);
}

public AliasConflictException(String message, Throwable reason) {
super(message, reason);
}

}
9 changes: 5 additions & 4 deletions src/main/java/i5/las2peer/p2p/AliasNotFoundException.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

public class AliasNotFoundException extends Exception {

/**
*
*/
private static final long serialVersionUID = 1L;

public AliasNotFoundException(String message, Exception reason) {
public AliasNotFoundException(String message) {
super(message);
}

public AliasNotFoundException(String message, Throwable reason) {
super(message, reason);
}

Expand Down
10 changes: 0 additions & 10 deletions src/main/java/i5/las2peer/p2p/DuplicateServiceAliasException.java

This file was deleted.

107 changes: 55 additions & 52 deletions src/main/java/i5/las2peer/p2p/Node.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,5 @@
package i5.las2peer.p2p;

import java.io.File;
import java.io.Serializable;
import java.lang.management.ManagementFactory;
import java.lang.reflect.InvocationTargetException;
import java.security.KeyPair;
import java.security.PublicKey;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Vector;

import com.sun.management.OperatingSystemMXBean;

import i5.las2peer.api.exceptions.ArtifactNotFoundException;
import i5.las2peer.api.exceptions.EnvelopeAlreadyExistsException;
import i5.las2peer.api.exceptions.StorageException;
Expand All @@ -47,9 +26,9 @@
import i5.las2peer.persistency.Envelope;
import i5.las2peer.persistency.NodeStorageInterface;
import i5.las2peer.security.Agent;
import i5.las2peer.security.AgentContext;
import i5.las2peer.security.AgentException;
import i5.las2peer.security.AgentStorage;
import i5.las2peer.security.AgentContext;
import i5.las2peer.security.GroupAgent;
import i5.las2peer.security.L2pSecurityException;
import i5.las2peer.security.Mediator;
Expand All @@ -64,10 +43,32 @@
import i5.las2peer.tools.CryptoException;
import i5.las2peer.tools.CryptoTools;
import i5.las2peer.tools.SerializationException;

import java.io.File;
import java.io.Serializable;
import java.lang.management.ManagementFactory;
import java.lang.reflect.InvocationTargetException;
import java.security.KeyPair;
import java.security.PublicKey;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Vector;

import rice.pastry.NodeHandle;
import rice.pastry.PastryNode;
import rice.pastry.socket.SocketNodeHandle;

import com.sun.management.OperatingSystemMXBean;

/**
* Base class for nodes in the las2peer environment.
*
Expand Down Expand Up @@ -102,11 +103,13 @@ public enum NodeStatus {
*/
private OperatingSystemMXBean osBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory
.getOperatingSystemMXBean();
public static final double DEFAULT_CPU_LOAD_TRESHOLD = 0.5;
private double cpuLoadThreshold = DEFAULT_CPU_LOAD_TRESHOLD; // TODO: make it configurable

private NodeServiceCache nodeServiceCache;
// TODO make time as setting
// should be lowered in future, currently services don't change often

// TODO make node parameters configurable:
public static final double DEFAULT_CPU_LOAD_TRESHOLD = 0.5;
private double cpuLoadThreshold = DEFAULT_CPU_LOAD_TRESHOLD;
// should be lowered in future, currently services don't change often:
private int nodeServiceCacheLifetime = 60; // time before cached node info becomes invalidated
private int nodeServiceCacheResultCount = 3; // number of service instances to be collected from the network
private int tidyUpTimerInterval = 60;
Expand Down Expand Up @@ -268,8 +271,8 @@ public void removeObserver(NodeObserver observer) {
* @param service The service that should be monitored.
*/
public void setServiceMonitoring(ServiceAgent service) {
observerNotice(Event.SERVICE_ADD_TO_MONITORING, this.getNodeId(), service.getId(), null, null,
service.getServiceNameVersion().toString());
observerNotice(Event.SERVICE_ADD_TO_MONITORING, this.getNodeId(), service.getId(), null, null, service
.getServiceNameVersion().toString());
}

/**
Expand Down Expand Up @@ -553,8 +556,8 @@ public synchronized void shutDown() {
* @throws AgentException any problem with the agent itself (probably on calling
* {@link i5.las2peer.security.Agent#notifyRegistrationTo}
*/
public void registerReceiver(MessageReceiver receiver)
throws AgentAlreadyRegisteredException, L2pSecurityException, AgentException {
public void registerReceiver(MessageReceiver receiver) throws AgentAlreadyRegisteredException,
L2pSecurityException, AgentException {

// TODO allow multiple mediators registered at the same time for one agent to avoid conflicts between connectors

Expand All @@ -579,8 +582,8 @@ public void registerReceiver(MessageReceiver receiver)
try {
storeAgent(agent);
} catch (AgentAlreadyRegisteredException e) {
System.out.println(
"Just for notice - not an error: tried to store an already known agent before registering");
System.out
.println("Just for notice - not an error: tried to store an already known agent before registering");
// nothing to do
}
}
Expand Down Expand Up @@ -813,8 +816,8 @@ public abstract void sendMessage(Message message, Object atNodeId, MessageResult
* @throws NodeNotFoundException
* @throws L2pSecurityException
*/
public void sendResponse(Message message, Object atNodeId)
throws AgentNotKnownException, NodeNotFoundException, L2pSecurityException {
public void sendResponse(Message message, Object atNodeId) throws AgentNotKnownException, NodeNotFoundException,
L2pSecurityException {
sendMessage(message, atNodeId, null);
}

Expand Down Expand Up @@ -1085,8 +1088,8 @@ public ServiceAgent[] getRegisteredServices() {
* @throws L2pSecurityException
* @throws AgentAlreadyRegisteredException
*/
public Mediator createMediatorForAgent(Agent agent)
throws AgentNotKnownException, L2pSecurityException, AgentAlreadyRegisteredException {
public Mediator createMediatorForAgent(Agent agent) throws AgentNotKnownException, L2pSecurityException,
AgentAlreadyRegisteredException {
if (agent.isLocked()) {
throw new L2pSecurityException("You need to unlock the agent for mediation!");
}
Expand All @@ -1111,8 +1114,8 @@ public Mediator createMediatorForAgent(Agent agent)
* @throws L2pSecurityException
* @throws AgentException
*/
public abstract void storeAgent(Agent agent)
throws AgentAlreadyRegisteredException, L2pSecurityException, AgentException;
public abstract void storeAgent(Agent agent) throws AgentAlreadyRegisteredException, L2pSecurityException,
AgentException;

/**
* Updates an existing agent of the network.
Expand Down Expand Up @@ -1271,8 +1274,8 @@ public Serializable invoke(Agent executing, ServiceNameVersion service, String m
* @throws InterruptedException
*/
public Serializable invoke(Agent executing, ServiceNameVersion service, String method, Serializable[] parameters,
boolean exactVersion)
throws L2pSecurityException, AgentNotKnownException, L2pServiceException, InterruptedException {
boolean exactVersion) throws L2pSecurityException, AgentNotKnownException, L2pServiceException,
InterruptedException {
return invoke(executing, service, method, parameters, exactVersion, false);
}

Expand All @@ -1293,8 +1296,8 @@ public Serializable invoke(Agent executing, ServiceNameVersion service, String m
* @throws InterruptedException
*/
public Serializable invoke(Agent executing, ServiceNameVersion service, String method, Serializable[] parameters,
boolean exactVersion, boolean localOnly)
throws L2pSecurityException, AgentNotKnownException, L2pServiceException, InterruptedException {
boolean exactVersion, boolean localOnly) throws L2pSecurityException, AgentNotKnownException,
L2pServiceException, InterruptedException {

if (getStatus() != NodeStatus.RUNNING) {
throw new IllegalStateException("You can invoke methods only on a running node!");
Expand Down Expand Up @@ -1350,8 +1353,8 @@ public Serializable invoke(Agent executing, ServiceNameVersion service, String m
* @throws L2pServiceException
*/
public Serializable invokeLocally(Agent executing, ServiceAgent serviceAgent, String method,
Serializable[] parameters)
throws L2pSecurityException, AgentNotKnownException, InterruptedException, L2pServiceException {
Serializable[] parameters) throws L2pSecurityException, AgentNotKnownException, InterruptedException,
L2pServiceException {

if (getStatus() != NodeStatus.RUNNING) {
throw new IllegalStateException("You can invoke methods only on a running node!");
Expand Down Expand Up @@ -1491,10 +1494,10 @@ public Serializable invokeGlobally(Agent executing, long serviceAgentId, Object
return ((RMIResultContent) resultContent).getContent();
} else {
// Do not log service class name (privacy..)
this.observerNotice(Event.RMI_FAILED, this.getNodeId(), executing,
"Unknown RMI response type: " + resultContent.getClass().getCanonicalName());
throw new ServiceInvocationException(
"Unknown RMI response type: " + resultContent.getClass().getCanonicalName());
this.observerNotice(Event.RMI_FAILED, this.getNodeId(), executing, "Unknown RMI response type: "
+ resultContent.getClass().getCanonicalName());
throw new ServiceInvocationException("Unknown RMI response type: "
+ resultContent.getClass().getCanonicalName());
}
} catch (AgentNotKnownException e) {
// Do not log service class name (privacy..)
Expand Down Expand Up @@ -1551,8 +1554,8 @@ public boolean handoverAnswer(Message answer) {
return false;
}

observerNotice(Event.MESSAGE_RECEIVED_ANSWER, answer.getSendingNodeId(), answer.getSenderId(), this.getNodeId(),
answer.getRecipientId(), "" + answer.getResponseToId());
observerNotice(Event.MESSAGE_RECEIVED_ANSWER, answer.getSendingNodeId(), answer.getSenderId(),
this.getNodeId(), answer.getRecipientId(), "" + answer.getResponseToId());

MessageResultListener listener = htAnswerListeners.get(answer.getResponseToId());
if (listener == null) {
Expand Down Expand Up @@ -1627,8 +1630,8 @@ public Message sendMessageAndWaitForAnswer(Message m, Object atNodeId) throws Ag
* @throws InterruptedException
* @throws TimeoutException
*/
public Message[] sendMessageAndCollectAnswers(Message m, int recipientCount)
throws InterruptedException, TimeoutException {
public Message[] sendMessageAndCollectAnswers(Message m, int recipientCount) throws InterruptedException,
TimeoutException {
long timeout = m.getTimeoutTs() - new Date().getTime();
MessageResultListener listener = new MessageResultListener(timeout, timeout / 4);
listener.addRecipients(recipientCount);
Expand Down
Loading

0 comments on commit d9ee916

Please sign in to comment.