summaryrefslogtreecommitdiff
path: root/src/main/java/net/transit/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/net/transit/network')
-rw-r--r--src/main/java/net/transit/network/packet/ArrayPacket.java45
-rw-r--r--src/main/java/net/transit/network/packet/IPacket.java23
-rw-r--r--src/main/java/net/transit/network/packet/MetaPacket.java33
-rw-r--r--src/main/java/net/transit/network/packet/StaticPacket.java25
-rw-r--r--src/main/java/net/transit/network/swap/IAcceptor.java31
-rw-r--r--src/main/java/net/transit/network/swap/IProvider.java37
-rw-r--r--src/main/java/net/transit/network/system/INode.java50
-rw-r--r--src/main/java/net/transit/network/system/ISystem.java17
8 files changed, 261 insertions, 0 deletions
diff --git a/src/main/java/net/transit/network/packet/ArrayPacket.java b/src/main/java/net/transit/network/packet/ArrayPacket.java
new file mode 100644
index 0000000..9cbd300
--- /dev/null
+++ b/src/main/java/net/transit/network/packet/ArrayPacket.java
@@ -0,0 +1,45 @@
+package net.transit.network.packet;
+
+import java.util.ArrayList;
+
+import net.transit.type.Type;
+
+public class ArrayPacket<D> implements IPacket<D>
+{
+ private ArrayList<D> arrayData;
+ private Type<D> type;
+
+ public ArrayPacket(D startValue, Type<D> t)
+ {
+ arrayData = new ArrayList<D>(0);
+ arrayData.add(startValue);
+ }
+
+ public D getData()
+ {
+ if(arrayData.size() > 0) return arrayData.get(0);
+ return null;
+ }
+
+ public void addData(D data)
+ {
+ arrayData.add(data);
+ }
+
+ public D popAndShift()
+ {
+ D temp = null;
+
+ if(arrayData.size() > 0)
+ {
+ temp = arrayData.remove(0);
+ }
+
+ return temp;
+ }
+
+ @Override
+ public Type<D> getType() {
+ return type;
+ }
+} \ No newline at end of file
diff --git a/src/main/java/net/transit/network/packet/IPacket.java b/src/main/java/net/transit/network/packet/IPacket.java
new file mode 100644
index 0000000..deafdf8
--- /dev/null
+++ b/src/main/java/net/transit/network/packet/IPacket.java
@@ -0,0 +1,23 @@
+package net.transit.network.packet;
+
+import net.transit.type.Type;
+
+/**
+ * @author Kyle Gunger
+ *
+ * @param <D> The data type (Object) that the packet transfers.
+ */
+public interface IPacket<D>
+{
+ /**Get the packet's data
+ *
+ * @return <D> The packet's data
+ */
+ public D getData();
+
+ /**Get the packet's type
+ *
+ * @return IType<<D>> The type of the packet
+ */
+ public Type<D> getType();
+} \ No newline at end of file
diff --git a/src/main/java/net/transit/network/packet/MetaPacket.java b/src/main/java/net/transit/network/packet/MetaPacket.java
new file mode 100644
index 0000000..e4cffdf
--- /dev/null
+++ b/src/main/java/net/transit/network/packet/MetaPacket.java
@@ -0,0 +1,33 @@
+package net.transit.network.packet;
+
+import net.transit.type.Type;
+
+public class MetaPacket<D, M> implements IPacket<D>
+{
+
+ private D data;
+ private M metaData;
+ private Type<D> type;
+
+ public MetaPacket(D dat, Type<D> t, M meta)
+ {
+ data = dat;
+ type = t;
+ metaData = meta;
+ }
+
+ public D getData()
+ {
+ return data;
+ }
+
+ public M getMetaData()
+ {
+ return metaData;
+ }
+
+ @Override
+ public Type<D> getType() {
+ return type;
+ }
+}
diff --git a/src/main/java/net/transit/network/packet/StaticPacket.java b/src/main/java/net/transit/network/packet/StaticPacket.java
new file mode 100644
index 0000000..8399041
--- /dev/null
+++ b/src/main/java/net/transit/network/packet/StaticPacket.java
@@ -0,0 +1,25 @@
+package net.transit.network.packet;
+
+import net.transit.type.Type;
+
+public class StaticPacket<D> implements IPacket<D>
+{
+ private D data;
+ private Type<D> type;
+
+ public StaticPacket(D dat, Type<D> t)
+ {
+ data = dat;
+ type = t;
+ }
+
+ public D getData()
+ {
+ return data;
+ }
+
+ @Override
+ public Type<D> getType() {
+ return type;
+ }
+} \ No newline at end of file
diff --git a/src/main/java/net/transit/network/swap/IAcceptor.java b/src/main/java/net/transit/network/swap/IAcceptor.java
new file mode 100644
index 0000000..6966b9a
--- /dev/null
+++ b/src/main/java/net/transit/network/swap/IAcceptor.java
@@ -0,0 +1,31 @@
+package net.transit.network.swap;
+
+import net.transit.network.packet.IPacket;
+
+/**
+ * @author Kyle Gunger
+ *
+ * @param <T> The type of data accepted (in IPacket<<T>> form)
+ */
+public interface IAcceptor<T>
+{
+ /**
+ * @return <b>True</b> if the acceptor can accept packets.
+ */
+ public boolean canAccept();
+
+ /**
+ * @param provided The packet provided.
+ * @return <b>True</b> if the acceptor accepted the packet.
+ */
+ public boolean accept(IPacket<T> provided);
+
+ /**
+ * @return <b>True</b> if the acceptor has a provider assigned to it.
+ */
+ public boolean hasProvider();
+
+ /**Set the provider of the acceptor. The acceptor can decide if it wants to adopt the provider.
+ */
+ public void setProvider(IProvider<T> provider);
+} \ No newline at end of file
diff --git a/src/main/java/net/transit/network/swap/IProvider.java b/src/main/java/net/transit/network/swap/IProvider.java
new file mode 100644
index 0000000..03c9ca9
--- /dev/null
+++ b/src/main/java/net/transit/network/swap/IProvider.java
@@ -0,0 +1,37 @@
+package net.transit.network.swap;
+
+import net.transit.network.packet.IPacket;
+
+/**
+ * @author Kyle Gunger
+ *
+ * @param <T> The type of data provided (in IPacket<<T>> form)
+ */
+public interface IProvider<T>
+{
+ /**
+ * @return <b>True</b> if the provider can provide a packet.
+ */
+ public boolean canProvide();
+
+ /**Get the next packet from the provider
+ *
+ * @return IPacket<<T>>
+ */
+ public IPacket<T> provide();
+
+ /**Retain the packet if the acceptor did not accept the packet.
+ *
+ * @param rejected The rejected packet
+ */
+ public void retain(IPacket<T> rejected);
+
+ /**
+ * @return <b>True</b> if the acceptor has a provider assigned to it
+ */
+ public boolean hasAcceptor();
+
+ /**Set the acceptor of the provider. The provider can decide if it wants to adopt the acceptor.
+ */
+ public void setAcceptor();
+} \ No newline at end of file
diff --git a/src/main/java/net/transit/network/system/INode.java b/src/main/java/net/transit/network/system/INode.java
new file mode 100644
index 0000000..2dc3686
--- /dev/null
+++ b/src/main/java/net/transit/network/system/INode.java
@@ -0,0 +1,50 @@
+package net.transit.network.system;
+
+import net.transit.network.swap.IAcceptor;
+import net.transit.network.swap.IProvider;
+
+/**
+ * @author Kyle Gunger
+ * @apiNote A node inside or outside a system. Provides acceptors and providers to other nodes.
+ */
+public interface INode
+{
+ /**Returns the groupIDs of groups the node provide
+ *
+ * @return String[]
+ */
+ public String[] groupsProvided();
+
+ /**Get the system managing the node or {@code null} if there isn't one
+ *
+ * @return ISystem
+ */
+ public ISystem getSystem();
+
+ /**Returns {@code true} if the node provides IAcceptors
+ *
+ * @return boolean
+ */
+ public boolean isAcceptor();
+
+ /**Returns an IAcceptor or {@code null} depending on the requester and group
+ *
+ * @param requester The object requesting the IAcceptor
+ * @param group
+ * @return IAcceptor
+ */
+ public IAcceptor<?> requestAcceptor(Object requester, String group);
+
+ /**Returns {@code true} if the node provides IProviders
+ *
+ */
+ public boolean isProvider();
+
+ /**Returns an IProvider or {@code null} depending on the requester and group
+ *
+ * @param requester The object requesting the IProvider
+ * @param group
+ * @return IProvider
+ */
+ public IProvider<?> requestProvider(Object requestor, String group);
+}
diff --git a/src/main/java/net/transit/network/system/ISystem.java b/src/main/java/net/transit/network/system/ISystem.java
new file mode 100644
index 0000000..fd2fa51
--- /dev/null
+++ b/src/main/java/net/transit/network/system/ISystem.java
@@ -0,0 +1,17 @@
+package net.transit.network.system;
+
+
+/**ISystem - a group of nodes optimized for performance
+ *
+ * A node can exist without a system, but a system can not exist without at least one root node.
+ *
+ * @param T The object type stored in the system.
+ */
+public interface ISystem
+{
+ /**The nodes stored by the system
+ *
+ * @return INode[]
+ */
+ public INode[] getNodes();
+}