Commit 71cab85f authored by Roland Kluge's avatar Roland Kluge
Browse files

Complete first version of event-driven topology event API

parent 2a012d44
......@@ -29,4 +29,6 @@ package de.tudarmstadt.maki.simonstrator.api.component.topology;
public interface ObservableTopologyProvider extends TopologyProvider {
public void addTopologyObserver(TopologyObserver observer);
// TODO@rkluge: addDeltaBased...
}
......@@ -7,16 +7,16 @@ package de.tudarmstadt.maki.simonstrator.api.component.topology;
*/
public class TopologyChangedEvent implements ITopologyChangedEvent {
public final TopologyProvider topology;
public final TopologyID topologyIdentifier;
protected final TopologyProvider topologyProvider;
protected final TopologyID topologyIdentifier;
public TopologyChangedEvent(final TopologyProvider topology, final TopologyID topologyIdentifier) {
this.topology = topology;
public TopologyChangedEvent(final TopologyProvider topologyProvider, final TopologyID topologyIdentifier) {
this.topologyProvider = topologyProvider;
this.topologyIdentifier = topologyIdentifier;
}
public TopologyProvider getTopologyProvider() {
return topology;
return topologyProvider;
}
public TopologyID getTopologyIdentifier() {
......@@ -25,7 +25,7 @@ public class TopologyChangedEvent implements ITopologyChangedEvent {
@Override
public String toString() {
return "TopologyChangedEvent";
return String.format("TopologyChangedEvent [provider=%s, ID=%s]", topologyProvider, topologyIdentifier);
}
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tudarmstadt.maki.simonstrator.api.component.topology.event;
import de.tudarmstadt.maki.simonstrator.api.component.topology.TopologyID;
import de.tudarmstadt.maki.simonstrator.api.component.topology.TopologyProvider;
public class ComplexTopologyChangeEvent extends DeltaBasedTopologyEvent {
private static final String INDENTATION_OF_CHILD_EVENTS = " ";
private Iterable<? extends DeltaBasedTopologyEvent> childEvents;
public ComplexTopologyChangeEvent(TopologyProvider topologyProvider, TopologyID topologyIdentifier,
final Iterable<? extends DeltaBasedTopologyEvent> childEvents) {
super(topologyProvider, topologyIdentifier);
this.childEvents = childEvents;
}
public Iterable<? extends DeltaBasedTopologyEvent> getChildEvents() {
return childEvents;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ComplexTopologyChangeEvent [topology=");
builder.append(topologyProvider);
builder.append(", topoId=");
builder.append(topologyIdentifier);
builder.append(", childEvents=[\n");
for (final DeltaBasedTopologyEvent childEvent : childEvents) {
builder.append(INDENTATION_OF_CHILD_EVENTS);
builder.append(childEvent.toString().replaceAll("\\n", "\n" + INDENTATION_OF_CHILD_EVENTS));
builder.append("\n");
}
builder.append("]]");
return builder.toString();
}
}
......@@ -20,25 +20,14 @@
package de.tudarmstadt.maki.simonstrator.api.component.topology.event;
public interface AtomicTopologyChangeEventObserver {
void preEdgeAddition(EdgeEvent event);
void postEdgeAddition(EdgeEvent event);
void preEdgeRemoval(EdgeEvent event);
void postEdgeRemoval(EdgeEvent event);
void preNodeAddition(NodeEvent event);
void postNodeAddition(NodeEvent event);
void preNodeRemoval(NodeEvent event);
void postNodeRemoval(NodeEvent event);
void preAttributeUpdate(GraphElementAttributeEvent event);
void postAttributeUpdate(GraphElementAttributeEvent event);
public interface DeltaBasedTopologyChangeObserver {
/**
* Invoked when a new {@link DeltaBasedTopologyEvent} occurs.
*
* @param event
* the event to handle
* @return (reserved for future use) null
*/
TopologyChangeEventResponse handleEvent(DeltaBasedTopologyEvent event);
}
......@@ -22,7 +22,7 @@ package de.tudarmstadt.maki.simonstrator.api.component.topology.event;
import de.tudarmstadt.maki.simonstrator.api.component.topology.ObservableTopologyProvider;
public interface AtomicTopologyChangeEventProvider extends ObservableTopologyProvider {
public interface DeltaBasedTopologyChangeProvider extends ObservableTopologyProvider {
public void addTopologyObserver(AtomicTopologyChangeEventObserver observer);
void addTopologyObserver(DeltaBasedTopologyChangeObserver observer);
}
......@@ -24,9 +24,13 @@ import de.tudarmstadt.maki.simonstrator.api.component.topology.TopologyChangedEv
import de.tudarmstadt.maki.simonstrator.api.component.topology.TopologyID;
import de.tudarmstadt.maki.simonstrator.api.component.topology.TopologyProvider;
public abstract class AtomicTopologyChangeEvent extends TopologyChangedEvent {
/**
* Root of the new topology event hierarchy
*/
public class DeltaBasedTopologyEvent extends TopologyChangedEvent {
public AtomicTopologyChangeEvent(TopologyProvider topology, TopologyID topologyIdentifier) {
super(topology, topologyIdentifier);
public DeltaBasedTopologyEvent(TopologyProvider topologyProvider, TopologyID topologyIdentifier) {
super(topologyProvider, topologyIdentifier);
}
}
......@@ -25,24 +25,35 @@ import de.tudarmstadt.maki.simonstrator.api.common.graph.IElement;
import de.tudarmstadt.maki.simonstrator.api.component.topology.TopologyID;
import de.tudarmstadt.maki.simonstrator.api.component.topology.TopologyProvider;
public class GraphElementAttributeEvent extends AtomicTopologyChangeEvent {
public class GraphElementAttributeEvent<E extends IElement, T>
extends TopologyElementChangeEvent<E> {
private final IElement affectedElement;
private final GraphElementProperty<?> property;
private final GraphElementProperty<T> property;
private T oldValue;
public GraphElementAttributeEvent(final IElement element, final GraphElementProperty<?> property,
public GraphElementAttributeEvent(final GraphElementProperty<T> property, final T oldValue, final E element,
TopologyProvider topology, TopologyID topologyIdentifier) {
super(topology, topologyIdentifier);
this.affectedElement = element;
super(topology, topologyIdentifier, element, TopologyEventTypes.SET);
this.property = property;
this.oldValue = oldValue;
}
public IElement getAffectedElement() {
return affectedElement;
public T getOldValue() {
return oldValue;
}
public GraphElementProperty<?> getProperty() {
public GraphElementProperty<T> getProperty() {
return property;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GraphElementAttributeEvent [\n property=");
builder.append(property);
builder.append(",\n oldValue=");
builder.append(oldValue);
builder.append("\n]");
return builder.toString();
}
}
......@@ -24,17 +24,11 @@ import de.tudarmstadt.maki.simonstrator.api.common.graph.IEdge;
import de.tudarmstadt.maki.simonstrator.api.component.topology.TopologyID;
import de.tudarmstadt.maki.simonstrator.api.component.topology.TopologyProvider;
public class EdgeEvent extends AtomicTopologyChangeEvent {
public class IEdgeChangedEvent extends TopologyElementChangeEvent<IEdge> {
private final IEdge affectedEdge;
public EdgeEvent(final IEdge edge, final TopologyProvider topology, final TopologyID topologyIdentifier) {
super(topology, topologyIdentifier);
this.affectedEdge = edge;
}
public IEdge getAffectedEdge() {
return this.affectedEdge;
public IEdgeChangedEvent(TopologyProvider topology, TopologyID topologyIdentifier, IEdge affectedElement,
TopologyEventType eventType) {
super(topology, topologyIdentifier, affectedElement, eventType);
}
}
......@@ -24,17 +24,11 @@ import de.tudarmstadt.maki.simonstrator.api.common.graph.INode;
import de.tudarmstadt.maki.simonstrator.api.component.topology.TopologyID;
import de.tudarmstadt.maki.simonstrator.api.component.topology.TopologyProvider;
public class NodeEvent extends AtomicTopologyChangeEvent {
public class INodeChangedEvent extends TopologyElementChangeEvent<INode> {
private INode affectedNode;
public NodeEvent(final INode node, final TopologyProvider topology, final TopologyID topologyIdentifier) {
super(topology, topologyIdentifier);
this.affectedNode = node;
}
public INode getAffectedNode() {
return affectedNode;
public INodeChangedEvent(TopologyProvider topology, TopologyID topologyIdentifier, INode affectedElement,
TopologyEventType eventType) {
super(topology, topologyIdentifier, affectedElement, eventType);
}
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tudarmstadt.maki.simonstrator.api.component.topology.event;
/**
* For now, this is a placeholder to allow
* {@link DeltaBasedTopologyChangeObserver}s to react to events in the future.
*
* @author MAKI-A1
*/
public class TopologyChangeEventResponse {
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tudarmstadt.maki.simonstrator.api.component.topology.event;
import de.tudarmstadt.maki.simonstrator.api.common.graph.IElement;
import de.tudarmstadt.maki.simonstrator.api.component.topology.TopologyID;
import de.tudarmstadt.maki.simonstrator.api.component.topology.TopologyProvider;
public abstract class TopologyElementChangeEvent<E extends IElement> extends DeltaBasedTopologyEvent {
protected final E affectedElement;
protected final TopologyEventType eventType;
public TopologyElementChangeEvent(TopologyProvider topology, TopologyID topologyIdentifier, final E affectedElement,
final TopologyEventType eventType) {
super(topology, topologyIdentifier);
this.affectedElement = affectedElement;
this.eventType = eventType;
}
public E getAffectedElement() {
return affectedElement;
}
public TopologyEventType getEventType() {
return eventType;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("TopologyElementChangeEvent [\n affectedElement=");
builder.append(affectedElement);
builder.append(",\n eventType=");
builder.append(eventType);
builder.append("\n]");
return builder.toString();
}
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tudarmstadt.maki.simonstrator.api.component.topology.event;
public class TopologyEventType {
private final long id;
private final String name;
public TopologyEventType(final long id, final String name) {
this.id = id;
this.name = name;
}
public TopologyEventType(String string) {
this(string.hashCode(), string);
}
public long getId() {
return id;
}
public String getName() {
return name;
}
@Override
public String toString() {
return "TopologyEventType: " + name;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (getId() ^ (getId() >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TopologyEventType other = (TopologyEventType) obj;
if (getId() != other.getId())
return false;
return true;
}
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tudarmstadt.maki.simonstrator.api.component.topology.event;
public interface TopologyEventTypes {
public static final TopologyEventType ADD = new TopologyEventType("Add Event");
public static final TopologyEventType REMOVE = new TopologyEventType("Remove Event");
public static final TopologyEventType SET = new TopologyEventType("Set Event");
}
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