Commit d917f604 authored by Thibaut Démare's avatar Thibaut Démare

Add the 'add receiver' command

parent 0273e27d
......@@ -21,6 +21,7 @@ public class IKeywordGSAdditional implements IKeyword {
public static final String REMOVE_NODE_ATTRIBUTE = "gs_remove_node_attribute";
public static final String STEP = "gs_step";
//Receiver command
public static final String ADD_RECEIVER = "gs_add_receiver";
public static final String GET_EDGE_ATTRIBUTE = "gs_get_edge_attribute";
public static final String GET_NODE_ATTRIBUTE = "gs_get_node_attribute";
public static final String GET_GRAPH_ATTRIBUTE = "gs_get_graph_attribute";
......@@ -28,6 +29,7 @@ public class IKeywordGSAdditional implements IKeyword {
public static final String FLUSH = "gs_flush";
// Facets associated to a command
public static final String ATTRIBUTE_FILTER = "gs_attribute_name";
public static final String ATTRIBUTE_NAME = "gs_attribute_name";
public static final String ATTRIBUTE_VALUE = "gs_attribute_value";
public static final String EDGE_ID = "gs_edge_id";
......
package org.graphstream.gama.extension.receiver;
import java.util.HashSet;
import java.util.Set;
import msi.gama.precompiler.ISymbolKind;
import msi.gama.precompiler.GamlAnnotations.facet;
import msi.gama.precompiler.GamlAnnotations.facets;
import msi.gama.precompiler.GamlAnnotations.inside;
import msi.gama.precompiler.GamlAnnotations.symbol;
import msi.gama.runtime.IScope;
import msi.gama.runtime.exceptions.GamaRuntimeException;
import msi.gaml.descriptions.IDescription;
import msi.gaml.expressions.IExpression;
import msi.gaml.statements.AbstractStatement;
import msi.gaml.statements.IStatement;
import msi.gaml.types.IType;
import org.graphstream.gama.extension.GSManager;
import org.graphstream.gama.extension.IKeywordGSAdditional;
@symbol(name = IKeywordGSAdditional.ADD_RECEIVER, kind = ISymbolKind.SINGLE_STATEMENT, with_sequence = false)
@inside(kinds = { ISymbolKind.BEHAVIOR, ISymbolKind.SINGLE_STATEMENT })
@facets(value = { @facet(name = IKeywordGSAdditional.RECEIVERID, type = IType.STRING, optional = false),
@facet(name = IKeywordGSAdditional.HOST, type = IType.STRING, optional = false),
@facet(name = IKeywordGSAdditional.PORT, type = IType.INT, optional = false),
@facet(name = IKeywordGSAdditional.ATTRIBUTE_FILTER, type = IType.LIST, optional = true)})
public class AddReceiverStatement extends AbstractStatement implements IStatement{
final IExpression receiverid;
final IExpression host;
final IExpression port;
final IExpression filter;
public AddReceiverStatement(IDescription desc) {
super(desc);
receiverid = getFacet(IKeywordGSAdditional.RECEIVERID);
host = getFacet(IKeywordGSAdditional.HOST);
port = getFacet(IKeywordGSAdditional.PORT);
filter = getFacet(IKeywordGSAdditional.ATTRIBUTE_FILTER);
}
@Override
protected Object privateExecuteIn(IScope scope) throws GamaRuntimeException {
String r = (String)(receiverid.value(scope));
String h = (String)(host.value(scope));
int p = (Integer)(port.value(scope));
Set filterSet = new HashSet((msi.gama.util.GamaList) filter.value(scope));
if (filterSet.size() == 0)
filterSet = null;
GSManager.addReceiver(r, h, p, filterSet);
return null;
}
}
\ 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