Skip to content

Commit

Permalink
Merge pull request #55 from dma-ais/javadoc
Browse files Browse the repository at this point in the history
Adding or updating javadoc
  • Loading branch information
Andreas authored Nov 5, 2019
2 parents 85c858e + d69feef commit 5b57d85
Show file tree
Hide file tree
Showing 261 changed files with 15,381 additions and 2,973 deletions.
2 changes: 1 addition & 1 deletion ais-lib-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>dk.dma.ais.lib</groupId>
<artifactId>ais-parent</artifactId>
<version>2.4-SNAPSHOT</version>
<version>2.4</version>
</parent>

<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion ais-lib-communication/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>dk.dma.ais.lib</groupId>
<artifactId>ais-parent</artifactId>
<version>2.4-SNAPSHOT</version>
<version>2.4</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
64 changes: 45 additions & 19 deletions ais-lib-communication/src/main/java/dk/dma/ais/bus/AisBus.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

/**
* Bus for exchanging AIS packets
*
* <p>
* Thread safety by delegation
*/
@ThreadSafe
Expand All @@ -60,6 +60,9 @@ public class AisBus extends AisBusComponent implements Runnable {
private volatile int busPullMaxElements = 1000;
private volatile int busQueueSize = 10000;

/**
* Instantiates a new Ais bus.
*/
public AisBus() {

}
Expand All @@ -77,7 +80,6 @@ public synchronized void init() {
/**
* Start AisBus thread
*
* @return thread
*/
public synchronized void start() {
// Start thread
Expand Down Expand Up @@ -135,10 +137,11 @@ public void stopProviders() {
provider.cancel();
}
}

/**
* Push packets non-blocking on to the bus
* @param packet
*
* @param packet the packet
* @return if pushing was a success
*/
public boolean push(AisPacket packet) {
Expand All @@ -147,9 +150,9 @@ public boolean push(AisPacket packet) {

/**
* Push element onto the bus. Returns false if the bus is overflowing
*
* @param packet
* @param blocking
*
* @param packet the packet
* @param blocking the blocking
* @return if pushing was a success
*/
public boolean push(AisPacket packet, boolean blocking) {
Expand Down Expand Up @@ -181,10 +184,11 @@ public boolean push(AisPacket packet, boolean blocking) {
}
return true;
}

/**
* Get the average overflow rate experienced by all providers
* @return
*
* @return double double
*/
public double avgOverflowRate() {
double sum = 0;
Expand All @@ -198,20 +202,21 @@ public double avgOverflowRate() {

/**
* Register a consumer
*
* @param consumer
*
* @param consumer the consumer
*/
public void registerConsumer(AisBusConsumer consumer) {
// Tie aisbus to consumer
consumer.setAisBus(this);
// Make consumer queue
consumers.add(consumer);
}

/**
* Get consumer by name
* @param name
* @return
*
* @param name the name
* @return consumer consumer
*/
public AisBusConsumer getConsumer(String name) {
for (AisBusConsumer consumer : consumers) {
Expand All @@ -221,11 +226,12 @@ public AisBusConsumer getConsumer(String name) {
}
return null;
}

/**
* Get provider by name
* @param name
* @return
*
* @param name the name
* @return provider provider
*/
public AisBusProvider getProvider(String name) {
for (AisBusProvider provider : providers) {
Expand All @@ -238,8 +244,8 @@ public AisBusProvider getProvider(String name) {

/**
* Register a provider
*
* @param provider
*
* @param provider the provider
*/
public void registerProvider(AisBusProvider provider) {
// Tie aisbus to provider
Expand Down Expand Up @@ -279,18 +285,38 @@ public void run() {
LOG.info("Stopped");
}

/**
* Sets bus pull max elements.
*
* @param busPullMaxElements the bus pull max elements
*/
public void setBusPullMaxElements(int busPullMaxElements) {
this.busPullMaxElements = busPullMaxElements;
}

/**
* Sets bus queue size.
*
* @param busQueueSize the bus queue size
*/
public void setBusQueueSize(int busQueueSize) {
this.busQueueSize = busQueueSize;
}

/**
* Gets consumers.
*
* @return the consumers
*/
public Set<AisBusConsumer> getConsumers() {
return Collections.unmodifiableSet(consumers);
}

/**
* Gets providers.
*
* @return the providers
*/
public Set<AisBusProvider> getProviders() {
return Collections.unmodifiableSet(providers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
@ThreadSafe
public abstract class AisBusComponent {

/**
* Maximum time to wait for threads to stop after having been cancelled
*/
Expand All @@ -56,6 +56,9 @@ public abstract class AisBusComponent {
*/
protected final CopyOnWriteArrayList<IAisPacketTransformer> packetTransformers = new CopyOnWriteArrayList<>();

/**
* Instantiates a new Ais bus component.
*/
public AisBusComponent() {
this.status = new AisBusComponentStatus();
}
Expand All @@ -73,55 +76,65 @@ public void init() {
public void start() {
status.setStarted();
}


/**
* Sets connected.
*/
public void setConnected() {
status.setConnected();
}


/**
* Sets not connected.
*/
public void setNotConnected() {
status.setNotConnected();
}


/**
* Sets stopped.
*/
public void setStopped() {
status.setStopped();
}

/**
* Get component status
* @return
*
* @return status status
*/
public AisBusComponentStatus getStatus() {
return status;
}

/**
* Set component thread
*
* @param thread
*
* @param thread the thread
*/
protected synchronized void setThread(Thread thread) {
this.thread = thread;
}

/**
* Get component thread
*
* @return
*
* @return thread thread
*/
public synchronized Thread getThread() {
return thread;
}

/**
* All components must implement a way to stop
* All components must implement a way to stop
*/
public abstract void cancel();

/**
* Method to handle incoming packet for all AisBus components. Will do filtering, transformation and tagging.
*
* @param element
* @return
*
* @param packet the packet
* @return ais packet
*/
protected AisPacket handleReceived(AisPacket packet) {
status.receive();
Expand All @@ -148,17 +161,17 @@ protected AisPacket handleReceived(AisPacket packet) {

/**
* Get filters collection
*
* @return
*
* @return filters filters
*/
public PacketFilterCollection getFilters() {
return filters;
}

/**
* Get packet transformers list
*
* @return
*
* @return packet transformers
*/
public CopyOnWriteArrayList<IAisPacketTransformer> getPacketTransformers() {
return packetTransformers;
Expand All @@ -174,7 +187,12 @@ public String toString() {
builder.append("]");
return builder.toString();
}


/**
* Rate report string.
*
* @return the string
*/
public String rateReport() {
return String.format("[received/filtered/overflow] %4.2f / %4.2f / %4.2f (packets/sec)", status.getInRate(), status.getFilteredRate(), status.getOverflowRate());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import dk.dma.ais.queue.MessageQueueOverflowException;
import dk.dma.ais.queue.MessageQueueReader;

/**
* The type Ais bus consumer.
*/
@ThreadSafe
public abstract class AisBusConsumer extends AisBusSocket implements IQueueEntryHandler<AisBusElement> {

Expand All @@ -39,10 +42,18 @@ public abstract class AisBusConsumer extends AisBusSocket implements IQueueEntry
@GuardedBy("this")
private int consumerPullMaxElements = 1000;

/**
* Instantiates a new Ais bus consumer.
*/
public AisBusConsumer() {
super();
}

/**
* Instantiates a new Ais bus consumer.
*
* @param blocking the blocking
*/
public AisBusConsumer(boolean blocking) {
super(blocking);
}
Expand All @@ -63,8 +74,8 @@ public final void receive(AisBusElement queueElement) {

/**
* Push elements onto the queue
*
* @param element
*
* @param element the element
*/
public final void push(AisBusElement element) {
try {
Expand Down Expand Up @@ -109,15 +120,25 @@ public void cancel() {

/**
* All consumers must implement a method to get the filtered packet
*
* @param queueElement
*
* @param queueElement the queue element
*/
public abstract void receiveFiltered(AisBusElement queueElement);

/**
* Sets consumer queue size.
*
* @param consumerQueueSize the consumer queue size
*/
public synchronized void setConsumerQueueSize(int consumerQueueSize) {
this.consumerQueueSize = consumerQueueSize;
}

/**
* Sets consumer pull max elements.
*
* @param consumerPullMaxElements the consumer pull max elements
*/
public synchronized void setConsumerPullMaxElements(int consumerPullMaxElements) {
this.consumerPullMaxElements = consumerPullMaxElements;
}
Expand Down
Loading

0 comments on commit 5b57d85

Please sign in to comment.