tom

Cleaned-up templates and added package.html files.

package org.onlab.onos.event;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Base implementation of a manager capable of tracking listeners and
......@@ -16,7 +16,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
public class AbstractListenerManager<E extends Event, L extends EventListener<E>>
implements EventSink<E> {
protected Logger log = LoggerFactory.getLogger(AbstractListenerManager.class);
private final Logger log = getLogger(getClass());
private final Set<L> listeners = new CopyOnWriteArraySet<>();
......
<body>
ONOS Core API definitions.
</body>
\ No newline at end of file
package org.onlab.onos.event.impl;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
import org.onlab.onos.event.AbstractEvent;
import org.onlab.onos.event.DefaultEventSinkBroker;
import org.onlab.onos.event.Event;
import org.onlab.onos.event.EventDispatchService;
import org.onlab.onos.event.EventSink;
import org.slf4j.Logger;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import static java.util.concurrent.Executors.newSingleThreadExecutor;
import static org.onlab.util.Tools.namedThreads;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Simple implementation of an event dispatching service.
*/
@Component(immediate = true)
@Service
public class SimpleEventDispatcher implements EventDispatchService {
public class SimpleEventDispatcher extends DefaultEventSinkBroker
implements EventDispatchService {
private final ExecutorService executor = Executors.newSingleThreadExecutor();
private final Logger log = getLogger(getClass());
@Override
public void post(Event event) {
private final ExecutorService executor =
newSingleThreadExecutor(namedThreads("event-dispatch-%d"));
}
@SuppressWarnings("unchecked")
private static final Event KILL_PILL = new AbstractEvent(null, 0) {
};
@Override
public <E extends Event> void addSink(Class<E> eventClass, EventSink<E> sink) {
private final BlockingQueue<Event> events = new LinkedBlockingQueue<>();
}
private volatile boolean stopped = false;
@Override
public <E extends Event> void removeSink(Class<E> eventClass) {
public void post(Event event) {
events.add(event);
}
@Activate
public void activate() {
stopped = false;
executor.execute(new DispatchLoop());
log.info("Started");
}
@Override
public <E extends Event> EventSink<E> getSink(Class<E> eventClass) {
return null;
@Deactivate
public void deactivate() {
stopped = true;
post(KILL_PILL);
log.info("Stopped");
}
@Override
public Set<Class<? extends Event>> getSinks() {
return null;
// Auxiliary event dispatching loop that feeds off the events queue.
private class DispatchLoop implements Runnable {
@Override
@SuppressWarnings("unchecked")
public void run() {
log.info("Dispatch loop initiated");
while (!stopped) {
try {
// Fetch the next event and if it is the kill-pill, bail
Event event = events.take();
if (event == KILL_PILL) {
break;
}
// Locate the sink for the event class and use it to
// process the event
EventSink sink = getSink(event.getClass());
if (sink != null) {
sink.process(event);
} else {
log.warn("No sink registered for event class {}",
event.getClass());
}
} catch (Throwable e) {
log.warn("Error encountered while dispatching event:", e);
}
}
log.info("Dispatch loop terminated");
}
}
}
......
......@@ -7,12 +7,12 @@ import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
import org.onlab.onos.GreetService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashSet;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Trivial implementation of the seed service to demonstrate component and
......@@ -22,7 +22,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
@Service
public class GreetManager implements GreetService {
private final Logger log = LoggerFactory.getLogger(getClass());
private final Logger log = getLogger(getClass());
private final Set<String> names = new HashSet<>();
......
......@@ -7,7 +7,8 @@ import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.onos.GreetService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Example of a component that does not provide any service, but consumes one.
......@@ -15,7 +16,7 @@ import org.slf4j.LoggerFactory;
@Component(immediate = true)
public class SomeOtherComponent {
private final Logger log = LoggerFactory.getLogger(SomeOtherComponent.class);
private final Logger log = getLogger(getClass());
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected GreetService service;
......
......@@ -3,6 +3,8 @@ package org.onlab.onos.net.trivial.impl;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.onos.event.AbstractListenerManager;
import org.onlab.onos.event.EventDispatchService;
......@@ -22,11 +24,11 @@ import org.onlab.onos.net.device.PortDescription;
import org.onlab.onos.net.provider.AbstractProviderBroker;
import org.onlab.onos.net.provider.AbstractProviderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Provides basic implementation of the device SB &amp; NB APIs.
......@@ -42,24 +44,25 @@ public class SimpleDeviceManager
public static final String DEVICE_DESCRIPTION_NULL = "Device description cannot be null";
public static final String PORT_DESCRIPTION_NULL = "Port description cannot be null";
private Logger log = LoggerFactory.getLogger(SimpleDeviceManager.class);
private final Logger log = getLogger(getClass());
private final AbstractListenerManager<DeviceEvent, DeviceListener>
listenerManager = new AbstractListenerManager<>();
private EventDispatchService eventDispatcher;
private final DeviceStore store = new DeviceStore();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
private EventDispatchService eventDispatcher;
@Activate
public void activate() {
// eventDispatcher.addSink(DeviceEvent.class, listenerManager);
eventDispatcher.addSink(DeviceEvent.class, listenerManager);
log.info("Started");
}
@Deactivate
public void deactivate() {
// eventDispatcher.removeSink(DeviceEvent.class);
eventDispatcher.removeSink(DeviceEvent.class);
log.info("Stopped");
}
......
......@@ -3,55 +3,56 @@ package org.onlab.onos.net.trivial.impl;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.onos.event.AbstractListenerManager;
import org.onlab.onos.event.EventDispatchService;
import org.onlab.onos.net.host.HostDescription;
import org.onlab.onos.net.host.HostEvent;
import org.onlab.onos.net.host.HostListener;
import org.onlab.onos.net.host.HostProvider;
import org.onlab.onos.net.host.HostProviderBroker;
import org.onlab.onos.net.host.HostProviderService;
import org.onlab.onos.net.provider.AbstractProviderBroker;
import org.onlab.onos.net.provider.AbstractProviderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Provides basic implementation of the host SB &amp; NB APIs.
*/
@Component(immediate = true)
@Service
public class SimpleHostManager implements HostProviderBroker {
public class SimpleHostManager
extends AbstractProviderBroker<HostProvider, HostProviderService>
implements HostProviderBroker {
private final Logger log = getLogger(getClass());
private final AbstractListenerManager<HostEvent, HostListener>
listenerManager = new AbstractListenerManager<>();
private Logger log = LoggerFactory.getLogger(SimpleHostManager.class);
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
private EventDispatchService eventDispatcher;
private final HostProviderBroker broker = new InternalBroker();
@Activate
public void activate() {
eventDispatcher.addSink(HostEvent.class, listenerManager);
log.info("Started");
}
@Deactivate
public void deactivate() {
eventDispatcher.removeSink(HostEvent.class);
log.info("Stopped");
}
@Override
public HostProviderService register(HostProvider provider) {
return broker.register(provider);
}
@Override
public void unregister(HostProvider provider) {
broker.unregister(provider);
}
// Internal delegate for tracking various providers and issuing them a
// personalized provider service.
private class InternalBroker extends AbstractProviderBroker<HostProvider, HostProviderService>
implements HostProviderBroker {
@Override
protected HostProviderService createProviderService(HostProvider provider) {
return new InternalHostProviderService(provider);
}
protected HostProviderService createProviderService(HostProvider provider) {
return new InternalHostProviderService(provider);
}
// Personalized host provider service issued to the supplied provider.
......
......@@ -3,55 +3,55 @@ package org.onlab.onos.net.trivial.impl;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.onos.event.AbstractListenerManager;
import org.onlab.onos.event.EventDispatchService;
import org.onlab.onos.net.link.LinkDescription;
import org.onlab.onos.net.link.LinkEvent;
import org.onlab.onos.net.link.LinkListener;
import org.onlab.onos.net.link.LinkProvider;
import org.onlab.onos.net.link.LinkProviderBroker;
import org.onlab.onos.net.link.LinkProviderService;
import org.onlab.onos.net.provider.AbstractProviderBroker;
import org.onlab.onos.net.provider.AbstractProviderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Provides basic implementation of the link SB &amp; NB APIs.
*/
@Component(immediate = true)
@Service
public class SimpleLinkManager implements LinkProviderBroker {
public class SimpleLinkManager
extends AbstractProviderBroker<LinkProvider, LinkProviderService>
implements LinkProviderBroker {
private final Logger log = getLogger(getClass());
private Logger log = LoggerFactory.getLogger(SimpleLinkManager.class);
private final AbstractListenerManager<LinkEvent, LinkListener>
listenerManager = new AbstractListenerManager<>();
private final LinkProviderBroker broker = new InternalBroker();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
private EventDispatchService eventDispatcher;
@Activate
public void activate() {
eventDispatcher.addSink(LinkEvent.class, listenerManager);
log.info("Started");
}
@Deactivate
public void deactivate() {
eventDispatcher.removeSink(LinkEvent.class);
log.info("Stopped");
}
@Override
public LinkProviderService register(LinkProvider provider) {
return broker.register(provider);
}
@Override
public void unregister(LinkProvider provider) {
broker.unregister(provider);
}
// Internal delegate for tracking various providers and issuing them a
// personalized provider service.
private class InternalBroker extends AbstractProviderBroker<LinkProvider, LinkProviderService>
implements LinkProviderBroker {
@Override
protected LinkProviderService createProviderService(LinkProvider provider) {
return new InternalLinkProviderService(provider);
}
protected LinkProviderService createProviderService(LinkProvider provider) {
return new InternalLinkProviderService(provider);
}
// Personalized link provider service issued to the supplied provider.
......
<body>
ONOS local event dispatching mechanism.
</body>
\ No newline at end of file
<body>
ONOS Core infrastructure implementations.
</body>
\ No newline at end of file
......@@ -26,6 +26,11 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.onlab.onos</groupId>
<artifactId>onlab-misc</artifactId>
</dependency>
</dependencies>
<build>
......
......@@ -112,6 +112,12 @@
<!-- ONOS related -->
<dependency>
<groupId>org.onlab.onos</groupId>
<artifactId>onlab-misc</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onlab.onos</groupId>
<artifactId>onos-api</artifactId>
<version>${project.version}</version>
</dependency>
......@@ -260,13 +266,13 @@
<group>
<title>Network Model &amp; Services</title>
<packages>
org.onlab.onos.*
org.onlab.onos:org.onlab.onos.*
</packages>
</group>
<group>
<title>Core Subsystems</title>
<packages>
org.onlab.onos.net.trivial.impl:org.onlab.onos.net.*.impl
org.onlab.onos.net.trivial.impl:org.onlab.onos.net.*.impl:org.onlab.onos.impl:org.onlab.onos.event.impl
</packages>
</group>
<group>
......
......@@ -12,8 +12,10 @@ import org.onlab.onos.net.device.DeviceProviderBroker;
import org.onlab.onos.net.device.DeviceProviderService;
import org.onlab.onos.net.provider.AbstractProvider;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.of.controller.OpenFlowController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Provider which uses an OpenFlow controller to detect network
......@@ -22,16 +24,15 @@ import org.slf4j.LoggerFactory;
@Component(immediate = true)
public class OpenFlowDeviceProvider extends AbstractProvider implements DeviceProvider {
private final Logger log = LoggerFactory.getLogger(OpenFlowDeviceProvider.class);
private final Logger log = getLogger(getClass());
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceProviderBroker providerBroker;
private DeviceProviderService providerService;
// @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
// protected OpenFlowController controller;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected OpenFlowController controller;
private DeviceProviderService providerService;
/**
* Creates an OpenFlow device provider.
......
......@@ -11,8 +11,10 @@ import org.onlab.onos.net.host.HostProviderBroker;
import org.onlab.onos.net.host.HostProviderService;
import org.onlab.onos.net.provider.AbstractProvider;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.of.controller.OpenFlowController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Provider which uses an OpenFlow controller to detect network
......@@ -21,15 +23,15 @@ import org.slf4j.LoggerFactory;
@Component(immediate = true)
public class OpenFlowHostProvider extends AbstractProvider implements HostProvider {
private final Logger log = LoggerFactory.getLogger(OpenFlowHostProvider.class);
private final Logger log = getLogger(getClass());
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected HostProviderBroker providerBroker;
private HostProviderService providerService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected OpenFlowController controller;
// @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
// protected OpenFlowController controller;
private HostProviderService providerService;
/**
* Creates an OpenFlow host provider.
......
......@@ -10,8 +10,10 @@ import org.onlab.onos.net.link.LinkProviderBroker;
import org.onlab.onos.net.link.LinkProviderService;
import org.onlab.onos.net.provider.AbstractProvider;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.of.controller.OpenFlowController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Provider which uses an OpenFlow controller to detect network
......@@ -20,15 +22,15 @@ import org.slf4j.LoggerFactory;
@Component(immediate = true)
public class OpenFlowLinkProvider extends AbstractProvider implements LinkProvider {
private final Logger log = LoggerFactory.getLogger(OpenFlowLinkProvider.class);
private final Logger log = getLogger(getClass());
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected LinkProviderBroker providerBroker;
private LinkProviderService providerService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected OpenFlowController controller;
// @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
// protected OpenFlowController controller;
private LinkProviderService providerService;
/**
* Creates an OpenFlow link provider.
......
......@@ -24,7 +24,11 @@
<dependency>
<groupId>org.onlab.onos</groupId>
<artifactId>onos-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onlab.onos</groupId>
<artifactId>onlab-misc</artifactId>
</dependency>
<dependency>
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onlab.onos</groupId>
<artifactId>onlab-utils</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onlab-misc</artifactId>
<packaging>bundle</packaging>
<description>Miscellaneous ON.Lab utilities</description>
<dependencies>
</dependencies>
</project>
package org.onlab.util;
public class Foo {
}
package org.onlab.util;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.util.concurrent.ThreadFactory;
public abstract class Tools {
private Tools() {
}
/**
* Returns a thread factory that produces threads named according to the
* supplied name pattern.
*
* @param pattern name pattern
* @return thread factory
*/
public static ThreadFactory namedThreads(String pattern) {
return new ThreadFactoryBuilder().setNameFormat(pattern).build();
}
}