Commit 386f353b authored by Thibaut Démare's avatar Thibaut Démare

Add some new stuff about receiver and a best management of exceptions

parent a7893412
...@@ -5,6 +5,9 @@ import java.util.HashMap; ...@@ -5,6 +5,9 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import msi.gama.runtime.exceptions.GamaRuntimeException;
import org.graphstream.gama.extension.receiver.GSReceiver;
import org.graphstream.gama.extension.sender.GSSender; import org.graphstream.gama.extension.sender.GSSender;
import org.graphstream.stream.sync.SinkTime; import org.graphstream.stream.sync.SinkTime;
...@@ -17,7 +20,9 @@ import org.graphstream.stream.sync.SourceTime; ...@@ -17,7 +20,9 @@ import org.graphstream.stream.sync.SourceTime;
* as methods to access senders and receivers by their id, to add and to remove * as methods to access senders and receivers by their id, to add and to remove
* them. * them.
* *
* @author Stefan Balev * This class is almost a copy of the one from gs-netlogo but updated to run with gama
*
* @author Stefan Balev, modified by Thibaut Dmare
* *
*/ */
public class GSManager { public class GSManager {
...@@ -26,7 +31,7 @@ public class GSManager { ...@@ -26,7 +31,7 @@ public class GSManager {
private static SinkTime sinkTime; private static SinkTime sinkTime;
private static Map<String, GSSender> senders; private static Map<String, GSSender> senders;
// private static Map<String, GSReceiver> receivers; private static Map<String, GSReceiver> receivers;
static { static {
sourceId = "gs-gama@" sourceId = "gs-gama@"
...@@ -35,22 +40,22 @@ public class GSManager { ...@@ -35,22 +40,22 @@ public class GSManager {
sinkTime = new SinkTime(); sinkTime = new SinkTime();
sourceTime.setSinkTime(sinkTime); sourceTime.setSinkTime(sinkTime);
senders = new HashMap<String, GSSender>(); senders = new HashMap<String, GSSender>();
// receivers = new HashMap<String, GSReceiver>(); receivers = new HashMap<String, GSReceiver>();
} }
public static GSSender getSender(String senderId) { public static GSSender getSender(String senderId) throws GamaRuntimeException {
GSSender sender = senders.get(senderId); GSSender sender = senders.get(senderId);
if (sender == null) if (sender == null)
System.out.println("Sender \"" + senderId throw new RuntimeException("Sender \"" + senderId
+ "\" does not exist"); + "\" does not exist");
return sender; return sender;
} }
public static void addSender(String senderId, String host, int port) { public static void addSender(String senderId, String host, int port) throws GamaRuntimeException {
GSSender sender = senders.get(senderId); GSSender sender = senders.get(senderId);
if (sender != null) if (sender != null)
System.out.println("Sender \"" + senderId throw new RuntimeException("Sender \"" + senderId
+ "\" already exists"); + "\" already exists");
sender = new GSSender(sourceId, sourceTime, host, port); sender = new GSSender(sourceId, sourceTime, host, port);
senders.put(senderId, sender); senders.put(senderId, sender);
...@@ -62,20 +67,20 @@ public class GSManager { ...@@ -62,20 +67,20 @@ public class GSManager {
senders.clear(); senders.clear();
} }
/*public static GSReceiver getReceiver(String receiverId) public static GSReceiver getReceiver(String receiverId)
throws ExtensionException { throws GamaRuntimeException {
GSReceiver receiver = receivers.get(receiverId); GSReceiver receiver = receivers.get(receiverId);
if (receiver == null) if (receiver == null)
throw new ExtensionException("Receiver \"" + receiverId throw new RuntimeException("Receiver \"" + receiverId
+ "\" does not exist"); + "\" does not exist");
return receiver; return receiver;
} }
public static void addReceiver(String receiverId, String host, int port, public static void addReceiver(String receiverId, String host, int port,
Set<String> attributeFilter) throws ExtensionException { Set<String> attributeFilter) throws GamaRuntimeException {
GSReceiver receiver = receivers.get(receiverId); GSReceiver receiver = receivers.get(receiverId);
if (receiver != null) if (receiver != null)
throw new ExtensionException("Receiver \"" + receiverId throw new RuntimeException("Receiver \"" + receiverId
+ "\" already exists"); + "\" already exists");
receiver = new GSReceiver(sinkTime, host, port, attributeFilter); receiver = new GSReceiver(sinkTime, host, port, attributeFilter);
receivers.put(receiverId, receiver); receivers.put(receiverId, receiver);
...@@ -85,5 +90,5 @@ public class GSManager { ...@@ -85,5 +90,5 @@ public class GSManager {
for (GSReceiver receiver : receivers.values()) for (GSReceiver receiver : receivers.values())
receiver.close(); receiver.close();
receivers.clear(); receivers.clear();
}*/ }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment