Commit f028f1f6 authored by legoc's avatar legoc
Browse files

Renamed status listener into event listener

parent 84b4e489
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<version>0.0.1</version> <version>0.0.1</version>
</parent> </parent>
<artifactId>cameo-api</artifactId> <artifactId>cameo-api</artifactId>
<version>0.1.7</version> <version>0.1.8-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties> <properties>
......
...@@ -45,7 +45,7 @@ public class Application { ...@@ -45,7 +45,7 @@ public class Application {
impl = new ApplicationImpl(args); impl = new ApplicationImpl(args);
server = new Server(impl.getEndpoint()); server = new Server(impl.getEndpoint());
server.registerStatusListener(impl.getEventListener()); server.registerEventListener(impl.getEventListener());
if (impl.getStarterEndpoint() != null) { if (impl.getStarterEndpoint() != null) {
starterServer = new Server(impl.getStarterEndpoint()); starterServer = new Server(impl.getStarterEndpoint());
......
...@@ -27,7 +27,7 @@ import java.util.concurrent.LinkedBlockingQueue; ...@@ -27,7 +27,7 @@ import java.util.concurrent.LinkedBlockingQueue;
*/ */
public class EventListener { public class EventListener {
protected String name = null; private String name = null;
private LinkedBlockingQueue<Event> eventQueue = new LinkedBlockingQueue<Event>(); private LinkedBlockingQueue<Event> eventQueue = new LinkedBlockingQueue<Event>();
/** /**
...@@ -47,7 +47,7 @@ public class EventListener { ...@@ -47,7 +47,7 @@ public class EventListener {
eventQueue.put(event); eventQueue.put(event);
} catch (InterruptedException e) { } catch (InterruptedException e) {
System.out.println("interrupted StatusListener while putting"); System.out.println("interrupted EventListener while putting");
} }
} }
...@@ -59,7 +59,7 @@ public class EventListener { ...@@ -59,7 +59,7 @@ public class EventListener {
return eventQueue.poll(); return eventQueue.poll();
} catch (InterruptedException e) { } catch (InterruptedException e) {
System.out.println("interrupted StatusListener while popping"); System.out.println("interrupted EventListener while popping");
return null; return null;
} }
} }
...@@ -73,7 +73,7 @@ public class EventListener { ...@@ -73,7 +73,7 @@ public class EventListener {
eventQueue.put(new CancelEvent(id, name)); eventQueue.put(new CancelEvent(id, name));
} catch (InterruptedException e) { } catch (InterruptedException e) {
System.out.println("interrupted StatusListener while putting"); System.out.println("interrupted EventListener while putting");
} }
} }
......
...@@ -106,12 +106,12 @@ public class Server { ...@@ -106,12 +106,12 @@ public class Server {
impl.terminate(); impl.terminate();
} }
public void registerStatusListener(EventListener listener) { public void registerEventListener(EventListener listener) {
impl.registerStatusListener(listener); impl.registerEventListener(listener);
} }
public void unregisterStatusListener(EventListener listener) { public void unregisterEventListener(EventListener listener) {
impl.unregisterStatusListener(listener); impl.unregisterEventListener(listener);
} }
/** /**
......
...@@ -52,8 +52,8 @@ class EventThread extends Thread { ...@@ -52,8 +52,8 @@ class EventThread extends Thread {
// Send event to listeners. // Send event to listeners.
// The EventListener contains the name attribute but not the application id because // The EventListener contains the name attribute but not the application id because
// the id is not available at the registration. // the id is not available at the registration.
ConcurrentLinkedDeque<EventListener> statusListeners = server.getEventListeners(); ConcurrentLinkedDeque<EventListener> eventListeners = server.getEventListeners();
for (EventListener listener : statusListeners) { for (EventListener listener : eventListeners) {
// If the application name is null, all the status are pushed // If the application name is null, all the status are pushed
// otherwise, filter on the name // otherwise, filter on the name
...@@ -76,8 +76,8 @@ class EventThread extends Thread { ...@@ -76,8 +76,8 @@ class EventThread extends Thread {
// Send event to listeners. // Send event to listeners.
// The EventListener contains the name attribute but not the application id because // The EventListener contains the name attribute but not the application id because
// the id is not available at the registration. // the id is not available at the registration.
ConcurrentLinkedDeque<EventListener> resultListeners = server.getEventListeners(); ConcurrentLinkedDeque<EventListener> eventListeners = server.getEventListeners();
for (EventListener listener : resultListeners) { for (EventListener listener : eventListeners) {
// Filter on the name // Filter on the name
if (listener.getName() != null && listener.getName().equals(result.getName())) { if (listener.getName() != null && listener.getName().equals(result.getName())) {
...@@ -91,8 +91,8 @@ class EventThread extends Thread { ...@@ -91,8 +91,8 @@ class EventThread extends Thread {
// Send event to listeners. // Send event to listeners.
// The EventListener contains the name attribute but not the application id because // The EventListener contains the name attribute but not the application id because
// the id is not available at the registration. // the id is not available at the registration.
ConcurrentLinkedDeque<EventListener> statusListeners = server.getEventListeners(); ConcurrentLinkedDeque<EventListener> eventListeners = server.getEventListeners();
for (EventListener listener : statusListeners) { for (EventListener listener : eventListeners) {
// If the application name is null, all the status are pushed // If the application name is null, all the status are pushed
// otherwise, filter on the name // otherwise, filter on the name
...@@ -108,8 +108,8 @@ class EventThread extends Thread { ...@@ -108,8 +108,8 @@ class EventThread extends Thread {
// Send event to listeners. // Send event to listeners.
// The EventListener contains the name attribute but not the application id because // The EventListener contains the name attribute but not the application id because
// the id is not available at the registration. // the id is not available at the registration.
ConcurrentLinkedDeque<EventListener> statusListeners = server.getEventListeners(); ConcurrentLinkedDeque<EventListener> eventListeners = server.getEventListeners();
for (EventListener listener : statusListeners) { for (EventListener listener : eventListeners) {
// If the application name is null, all the status are pushed // If the application name is null, all the status are pushed
// otherwise, filter on the name // otherwise, filter on the name
......
...@@ -83,10 +83,6 @@ public class InstanceImpl extends EventListener { ...@@ -83,10 +83,6 @@ public class InstanceImpl extends EventListener {
lastState = state; lastState = state;
} }
public String getName() {
return name;
}
public int getId() { public int getId() {
return id; return id;
} }
...@@ -104,7 +100,7 @@ public class InstanceImpl extends EventListener { ...@@ -104,7 +100,7 @@ public class InstanceImpl extends EventListener {
} }
public String getNameId() { public String getNameId() {
return name + "." + id; return getName() + "." + id;
} }
public boolean hasResult() { public boolean hasResult() {
...@@ -289,7 +285,7 @@ public class InstanceImpl extends EventListener { ...@@ -289,7 +285,7 @@ public class InstanceImpl extends EventListener {
} }
public int getActualState() { public int getActualState() {
List<Info> infos = server.getApplicationInfos(name); List<Info> infos = server.getApplicationInfos(getName());
for (Info info : infos) { for (Info info : infos) {
if (info.getId() == id) { if (info.getId() == id) {
...@@ -302,7 +298,7 @@ public class InstanceImpl extends EventListener { ...@@ -302,7 +298,7 @@ public class InstanceImpl extends EventListener {
public void terminate() { public void terminate() {
// Unregister the status. // Unregister the status.
server.unregisterStatusListener(this); server.unregisterEventListener(this);
// Unregister the waiting. // Unregister the waiting.
waiting.remove(); waiting.remove();
...@@ -381,7 +377,7 @@ public class InstanceImpl extends EventListener { ...@@ -381,7 +377,7 @@ public class InstanceImpl extends EventListener {
@Override @Override
public String toString() { public String toString() {
return name + "." + id + "@" + server.getEndpoint(); return getName() + "." + id + "@" + server.getEndpoint();
} }
} }
\ No newline at end of file
...@@ -138,11 +138,11 @@ public class ServerImpl extends ServicesImpl { ...@@ -138,11 +138,11 @@ public class ServerImpl extends ServicesImpl {
super.terminate(); super.terminate();
} }
public void registerStatusListener(EventListener listener) { public void registerEventListener(EventListener listener) {
eventListeners.add(listener); eventListeners.add(listener);
} }
public void unregisterStatusListener(EventListener listener) { public void unregisterEventListener(EventListener listener) {
eventListeners.remove(listener); eventListeners.remove(listener);
} }
...@@ -208,7 +208,7 @@ public class ServerImpl extends ServicesImpl { ...@@ -208,7 +208,7 @@ public class ServerImpl extends ServicesImpl {
// we set the name of the application and register before starting because the id is not available // we set the name of the application and register before starting because the id is not available
instance.setName(name); instance.setName(name);
registerStatusListener(instance); registerEventListener(instance);
try { try {
// we connect to the stream port before starting the application // we connect to the stream port before starting the application
...@@ -251,7 +251,7 @@ public class ServerImpl extends ServicesImpl { ...@@ -251,7 +251,7 @@ public class ServerImpl extends ServicesImpl {
// we set the name of the application and register before starting because the id is not available // we set the name of the application and register before starting because the id is not available
instance.setName(name); instance.setName(name);
registerStatusListener(instance); registerEventListener(instance);
try { try {
// we connect to the stream port before starting the application // we connect to the stream port before starting the application
...@@ -349,7 +349,7 @@ public class ServerImpl extends ServicesImpl { ...@@ -349,7 +349,7 @@ public class ServerImpl extends ServicesImpl {
// we set the name of the application and register before starting because the id is not available // we set the name of the application and register before starting because the id is not available
instance.setName(name); instance.setName(name);
registerStatusListener(instance); registerEventListener(instance);
int applicationId = applicationInfo.getId(); int applicationId = applicationInfo.getId();
...@@ -369,7 +369,7 @@ public class ServerImpl extends ServicesImpl { ...@@ -369,7 +369,7 @@ public class ServerImpl extends ServicesImpl {
} else { } else {
// it is important not to forget to unregister the result, otherwise a memory leak will occur // it is important not to forget to unregister the result, otherwise a memory leak will occur
unregisterStatusListener(instance); unregisterEventListener(instance);
} }
} }
......
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