Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
prisma-core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Descartes Research
prisma-core
Commits
32e9a0e8
Commit
32e9a0e8
authored
8 years ago
by
Simon Spinner
Browse files
Options
Downloads
Patches
Plain Diff
Introduce easier way to define notifications.
parent
aabe1f9d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools.descartes.prisma.core/src/tools/descartes/prisma/core/scopes/AgentScope.java
+42
-5
42 additions, 5 deletions
...re/src/tools/descartes/prisma/core/scopes/AgentScope.java
with
42 additions
and
5 deletions
tools.descartes.prisma.core/src/tools/descartes/prisma/core/scopes/AgentScope.java
+
42
−
5
View file @
32e9a0e8
package
tools.descartes.prisma.core.scopes
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
...
...
@@ -8,9 +9,11 @@ import java.util.Map;
import
org.eclipse.emf.ecore.EObject
;
import
org.eclipse.emf.ecore.resource.Resource
;
import
edu.kit.ipd.descartes.core.NamedElement
;
import
edu.kit.ipd.descartes.mm.adaptationpoints.AdaptationPointDescriptions
;
import
edu.kit.ipd.descartes.mm.adaptationpoints.AdaptationpointsFactory
;
import
tools.descartes.prisma.core.MessageBus
;
import
tools.descartes.prisma.core.MessageBus.ExchangeType
;
import
tools.descartes.prisma.core.MessageBus.Listener
;
import
tools.descartes.prisma.core.ModelRepository
;
import
tools.descartes.prisma.core.Transaction
;
...
...
@@ -39,9 +42,38 @@ public abstract class AgentScope extends Scope {
private
AdaptationPointDescriptions
adaptationPoints
;
private
final
SystemGlobalScope
systemScope
;
private
final
Map
<
String
,
AgentScope
>
scopeCache
=
new
HashMap
<>();
private
final
List
<
NotificationDefinition
>
notifications
=
new
ArrayList
<>();
protected
class
DelegationListener
implements
Listener
{
protected
class
NotificationDefinition
{
private
final
Class
<?>
key
;
private
final
String
exchange
;
private
final
ExchangeType
type
;
public
NotificationDefinition
(
Class
<?>
key
,
String
exchange
,
ExchangeType
type
)
{
this
.
key
=
key
;
this
.
exchange
=
exchange
;
this
.
type
=
type
;
}
public
void
create
()
{
getMessageBus
().
createExchange
(
exchange
,
type
);
}
public
boolean
isActive
(
Object
o
)
{
return
key
.
isInstance
(
o
);
}
public
void
send
(
String
notificationType
,
Object
o
)
{
getMessageBus
().
publishMessage
(
exchange
,
getRoutingKey
(
o
),
""
,
new
ModelNotification
(
getModelRepository
(),
notificationType
,
key
,
o
));
}
public
String
getRoutingKey
(
Object
o
)
{
return
((
NamedElement
)
o
).
getName
();
}
}
protected
class
DelegationListener
implements
Listener
{
@Override
public
void
newMessage
(
String
routingKey
,
Map
<
String
,
Object
>
headers
,
String
message
)
{
ModelNotification
notification
=
new
ModelNotification
(
getModelRepository
(),
headers
);
...
...
@@ -255,10 +287,11 @@ public abstract class AgentScope extends Scope {
}
public
void
sendNotifications
(
String
notificationType
,
EObject
object
)
{
}
protected
void
sendNotificationMessage
(
String
exchange
,
String
routingKey
,
ModelNotification
notification
)
{
getMessageBus
().
publishMessage
(
exchange
,
routingKey
,
""
,
notification
);
for
(
NotificationDefinition
curNotification
:
notifications
)
{
if
(
curNotification
.
isActive
(
object
))
{
curNotification
.
send
(
notificationType
,
object
);
}
}
}
public
void
addNotificationHandler
(
String
exchange
,
String
routingKey
,
final
AgentController
agent
)
{
...
...
@@ -273,4 +306,8 @@ public abstract class AgentScope extends Scope {
});
}
protected
void
declareNotification
(
NotificationDefinition
notification
)
{
this
.
notifications
.
add
(
notification
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment