Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simonstrator
API
Commits
71cab85f
Commit
71cab85f
authored
Aug 14, 2016
by
Roland Kluge
Browse files
Complete first version of event-driven topology event API
parent
2a012d44
Changes
13
Hide whitespace changes
Inline
Side-by-side
src/de/tudarmstadt/maki/simonstrator/api/component/topology/ObservableTopologyProvider.java
View file @
71cab85f
...
...
@@ -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...
}
src/de/tudarmstadt/maki/simonstrator/api/component/topology/TopologyChangedEvent.java
View file @
71cab85f
...
...
@@ -7,16 +7,16 @@ package de.tudarmstadt.maki.simonstrator.api.component.topology;
*/
public
class
TopologyChangedEvent
implements
ITopologyChangedEvent
{
p
ublic
final
TopologyProvider
topology
;
p
ublic
final
TopologyID
topologyIdentifier
;
p
rotected
final
TopologyProvider
topology
Provider
;
p
rotected
final
TopologyID
topologyIdentifier
;
public
TopologyChangedEvent
(
final
TopologyProvider
topology
,
final
TopologyID
topologyIdentifier
)
{
this
.
topology
=
topology
;
public
TopologyChangedEvent
(
final
TopologyProvider
topology
Provider
,
final
TopologyID
topologyIdentifier
)
{
this
.
topology
Provider
=
topology
Provider
;
this
.
topologyIdentifier
=
topologyIdentifier
;
}
public
TopologyProvider
getTopologyProvider
()
{
return
topology
;
return
topology
Provider
;
}
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
)
;
}
}
src/de/tudarmstadt/maki/simonstrator/api/component/topology/event/ComplexTopologyChangeEvent.java
0 → 100644
View file @
71cab85f
/*
* 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
();
}
}
src/de/tudarmstadt/maki/simonstrator/api/component/topology/event/
Atomic
TopologyChange
Event
Observer.java
→
src/de/tudarmstadt/maki/simonstrator/api/component/topology/event/
DeltaBased
TopologyChangeObserver.java
View file @
71cab85f
...
...
@@ -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
);
}
src/de/tudarmstadt/maki/simonstrator/api/component/topology/event/
Atomic
TopologyChange
Event
Provider.java
→
src/de/tudarmstadt/maki/simonstrator/api/component/topology/event/
DeltaBased
TopologyChangeProvider.java
View file @
71cab85f
...
...
@@ -22,7 +22,7 @@ package de.tudarmstadt.maki.simonstrator.api.component.topology.event;
import
de.tudarmstadt.maki.simonstrator.api.component.topology.ObservableTopologyProvider
;
public
interface
Atomic
TopologyChange
Event
Provider
extends
ObservableTopologyProvider
{
public
interface
DeltaBased
TopologyChangeProvider
extends
ObservableTopologyProvider
{
public
void
addTopologyObserver
(
Atomic
TopologyChange
Event
Observer
observer
);
void
addTopologyObserver
(
DeltaBased
TopologyChangeObserver
observer
);
}
src/de/tudarmstadt/maki/simonstrator/api/component/topology/event/
Atomic
Topology
Change
Event.java
→
src/de/tudarmstadt/maki/simonstrator/api/component/topology/event/
DeltaBased
TopologyEvent.java
View file @
71cab85f
...
...
@@ -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
Atomic
Topology
Change
Event
(
TopologyProvider
topology
,
TopologyID
topologyIdentifier
)
{
super
(
topology
,
topologyIdentifier
);
public
DeltaBased
TopologyEvent
(
TopologyProvider
topology
Provider
,
TopologyID
topologyIdentifier
)
{
super
(
topology
Provider
,
topologyIdentifier
);
}
}
src/de/tudarmstadt/maki/simonstrator/api/component/topology/event/GraphElementAttributeEvent.java
View file @
71cab85f
...
...
@@ -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
I
Element
affectedElement
;
private
final
GraphElementProperty
<?>
property
;
private
final
Graph
Element
Property
<
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
();
}
}
src/de/tudarmstadt/maki/simonstrator/api/component/topology/event/EdgeEvent.java
→
src/de/tudarmstadt/maki/simonstrator/api/component/topology/event/
I
Edge
Changed
Event.java
View file @
71cab85f
...
...
@@ -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
Atomic
TopologyChangeEvent
{
public
class
I
Edge
Changed
Event
extends
Topology
Element
ChangeEvent
<
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
);
}
}
src/de/tudarmstadt/maki/simonstrator/api/component/topology/event/NodeEvent.java
→
src/de/tudarmstadt/maki/simonstrator/api/component/topology/event/
I
Node
Changed
Event.java
View file @
71cab85f
...
...
@@ -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
Atomic
TopologyChangeEvent
{
public
class
I
Node
Changed
Event
extends
Topology
Element
ChangeEvent
<
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
);
}
}
src/de/tudarmstadt/maki/simonstrator/api/component/topology/event/TopologyChangeEventResponse.java
0 → 100644
View file @
71cab85f
/*
* 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
{
}
src/de/tudarmstadt/maki/simonstrator/api/component/topology/event/TopologyElementChangeEvent.java
0 → 100644
View file @
71cab85f
/*
* 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
();
}
}
src/de/tudarmstadt/maki/simonstrator/api/component/topology/event/TopologyEventType.java
0 → 100644
View file @
71cab85f
/*
* 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
;
}
}
src/de/tudarmstadt/maki/simonstrator/api/component/topology/event/TopologyEventTypes.java
0 → 100644
View file @
71cab85f
/*
* 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"
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment