summaryrefslogtreecommitdiff
path: root/src/main/java/net/cshift/api/transit/network
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2023-11-16 13:24:49 -0500
committerKyle Gunger <kgunger12@gmail.com>2023-11-16 13:24:49 -0500
commit20f2c0836b309a95cfcf0d9c13fafeefc5c1d5e7 (patch)
treec39040a546695c23233274e9e782902fb9588bd2 /src/main/java/net/cshift/api/transit/network
parentd1680864edfbc7cec0e6decf1e3a2b30f120aa0e (diff)
Change how GroupRegistry deals with Wildcard Generics
Diffstat (limited to 'src/main/java/net/cshift/api/transit/network')
-rw-r--r--src/main/java/net/cshift/api/transit/network/Channel.java12
-rw-r--r--src/main/java/net/cshift/api/transit/network/INode.java20
-rw-r--r--src/main/java/net/cshift/api/transit/network/ISystem.java15
-rw-r--r--src/main/java/net/cshift/api/transit/network/PoolManifest.java28
-rw-r--r--src/main/java/net/cshift/api/transit/network/packet/DynamicPacket.java14
-rw-r--r--src/main/java/net/cshift/api/transit/network/packet/IDynamicPacket.java13
-rw-r--r--src/main/java/net/cshift/api/transit/network/packet/IStaticPacket.java10
-rw-r--r--src/main/java/net/cshift/api/transit/network/packet/MetaDynamicPacket.java44
-rw-r--r--src/main/java/net/cshift/api/transit/network/packet/MetaPacket.java35
-rw-r--r--src/main/java/net/cshift/api/transit/network/packet/StaticPacket.java6
10 files changed, 55 insertions, 142 deletions
diff --git a/src/main/java/net/cshift/api/transit/network/Channel.java b/src/main/java/net/cshift/api/transit/network/Channel.java
index bd4cdf2..3fdae88 100644
--- a/src/main/java/net/cshift/api/transit/network/Channel.java
+++ b/src/main/java/net/cshift/api/transit/network/Channel.java
@@ -25,6 +25,8 @@
package net.cshift.api.transit.network;
import net.cshift.api.transit.network.packet.IStaticPacket;
+import net.cshift.api.transit.type.group.GroupRegistry;
+import net.cshift.api.transit.type.group.TypeGroup;
/**
* @author Kyle Gunger
@@ -35,6 +37,7 @@ public final class Channel<D> {
private INode to;
private int id;
private String group;
+ private Class<D> baseClass;
/** This constructor should be called by a node approving a connection. The approving node can give the connection an ID and group.
* Negative IDs indicate a terminated connection, so do not initialize the class with a negative ID.
@@ -43,11 +46,12 @@ public final class Channel<D> {
* @param id The channel's id, as assigned by the recieving node. In most cases, this will match the pool ID as a way to match channels to pools.
* @param group
*/
- public Channel(INode node, int id, String group)
+ public Channel(INode node, int id, String group, Class<D> baseClass)
{
to = node;
this.id = id;
this.group = group;
+ this.baseClass = baseClass;
}
@@ -78,8 +82,8 @@ public final class Channel<D> {
*
* @return
*/
- public String getGroup() {
- return group;
+ public TypeGroup<D> getGroup() {
+ return GroupRegistry.<D>groupByID(group, baseClass);
}
/** Returns true if the connection has been terminated
@@ -135,7 +139,7 @@ public final class Channel<D> {
* @param packet the packet to send
* @return The overflow data if the packet is only partially accepted. {@code null} otherwise.
*/
- public IStaticPacket<D> send(IStaticPacket<D> packet)
+ public IStaticPacket send(IStaticPacket packet)
{
return to.accept(packet, this);
}
diff --git a/src/main/java/net/cshift/api/transit/network/INode.java b/src/main/java/net/cshift/api/transit/network/INode.java
index 54701e7..6653e40 100644
--- a/src/main/java/net/cshift/api/transit/network/INode.java
+++ b/src/main/java/net/cshift/api/transit/network/INode.java
@@ -13,25 +13,29 @@ public interface INode
*/
public PoolManifest getManifest();
- /** Get the system managing the node or {@code null} if there isn't one
- *
- */
- public ISystem getSystem();
-
// ###############
// # Connections #
// ###############
- /** Call this function to establish a connection with a node.
+ /** Call this function to establish a specific connection with a node.
*
* @param <T> The type of connection being asked for
* @param poolID The ID of the pool the channel will interface with (see PoolManifest)
* @param asker The asking node
* @return A channel if the node accepts the request, {@code null} otherwise
*/
- public <T> Channel<T> connect(int poolID, INode asker);
+ public <T> Channel<T> connect(int poolID, String group, INode asker);
+
+ /** Call this function to establish a default connection with a node.
+ *
+ * @param <T> The type of connection being asked for
+ * @param group The group that is being connected to
+ * @param asker The asking node
+ * @return A channel if the node accepts the request, {@code null} otherwise
+ */
+ public <T> Channel<T> connectDefault(String group, INode asker);
/** Accept a packet from a channel (or not).
*
@@ -41,7 +45,7 @@ public interface INode
* @param channel The channel which the packet is coming through
* @return The overflow data if the packet is only partially accepted. {@code null} otherwise.
*/
- public <T> IStaticPacket<T> accept(IStaticPacket<T> packet, Channel<T> channel);
+ public IStaticPacket accept(IStaticPacket packet, Channel<?> channel);
/** Pressure
*
diff --git a/src/main/java/net/cshift/api/transit/network/ISystem.java b/src/main/java/net/cshift/api/transit/network/ISystem.java
deleted file mode 100644
index b7ab9bf..0000000
--- a/src/main/java/net/cshift/api/transit/network/ISystem.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package net.cshift.api.transit.network;
-
-
-/**
- * @author Kyle Gunger
- * @apiNote An ISystem represents a system of nodes which has been optimized for performance. A node can exist on its own, but an ISystem can't exist without a node.
- */
-public interface ISystem
-{
- /**The nodes stored by the system
- *
- * @return INode[]
- */
- public INode[] getNodes();
-}
diff --git a/src/main/java/net/cshift/api/transit/network/PoolManifest.java b/src/main/java/net/cshift/api/transit/network/PoolManifest.java
index 26cbece..e539ee1 100644
--- a/src/main/java/net/cshift/api/transit/network/PoolManifest.java
+++ b/src/main/java/net/cshift/api/transit/network/PoolManifest.java
@@ -6,35 +6,37 @@ package net.cshift.api.transit.network;
*/
public abstract class PoolManifest {
- /** Represents the number of pools that the node has access to for the specified resource.
- * @apiNote A "pool" in this context represents an independant network of resources.
+ /** Represents the number of pools that the node has access to.
+ * @apiNote A "pool" in this context represents an independent network of resources.
+ * Each network in the pool may represent a different TypeGroup.
* Pool zero should be the default group that simple nodes will attempt to connect to.
* @param group The TypeGroup that the pool belongs to
*/
- public abstract int poolCount(String group);
+ public abstract int poolCount();
- /** The ID of the pool. The INode will use this in a connection attempt with the other INode.
- *
- * @param group The TypeGroup the pool belongs to
- * @param pool Array-like index for pool (gotten from poolCount)
- */
- public abstract int poolID(String group, int pool);
-
- /** If the mod supports named pools, the names can be querried through this function.
+ /** If the mod supports named pools, the names can be queried through this function.
*
* @param group The TypeGroup the pool belongs to
* @param pool Array-like index for pool (gotten from poolCount)
*/
- public String poolName(String group, int pool) {
+ public String poolName(int pool) {
return "";
}
+
+ /** Returns true if the pool with the given id supports the given group
+ *
+ * @param pool The pool ID to query
+ * @param group The TypeGroup to query
+ * @return {@code true} if the pool supports the specified group, {@code false} otherwise
+ */
+ public abstract boolean poolProvides(int pool, String group);
/** If the mod supports pool descriptions, they can be accessed by this method.
*
* @param group The TypeGroup the pool belongs to
* @param pool Array-like index for pool (gotten from poolCount)
*/
- public String poolDescription(String group, int pool) {
+ public String poolDescription(int pool) {
return "";
}
}
diff --git a/src/main/java/net/cshift/api/transit/network/packet/DynamicPacket.java b/src/main/java/net/cshift/api/transit/network/packet/DynamicPacket.java
index f3a6c47..3a57227 100644
--- a/src/main/java/net/cshift/api/transit/network/packet/DynamicPacket.java
+++ b/src/main/java/net/cshift/api/transit/network/packet/DynamicPacket.java
@@ -3,14 +3,14 @@ package net.cshift.api.transit.network.packet;
import net.cshift.api.transit.type.Type;
/**
- * Simple packet which stores a fluid value.
+ * Simple packet which stores a value which can change.
*
+ * @param <D> The type parameter of the Type being transported
* @author Kyle Gunger
- *
- * @param <D> The data type (Object) that the packet transfers
+ *
*/
public class DynamicPacket<D> implements IDynamicPacket<D> {
- private D data;
+ private Object data;
private Type<D> type;
/** Constructor. Stores the given data and uses the given type.
@@ -18,20 +18,20 @@ public class DynamicPacket<D> implements IDynamicPacket<D> {
* @param dat The packet's data
* @param t The packet's type
*/
- public DynamicPacket(D dat, Type<D> t)
+ public DynamicPacket(Object dat, Type<D> t)
{
data = dat;
type = t;
}
@Override
- public D getData()
+ public Object getData()
{
return data;
}
@Override
- public void setData(D dat)
+ public void setData(Object dat)
{
data = dat;
}
diff --git a/src/main/java/net/cshift/api/transit/network/packet/IDynamicPacket.java b/src/main/java/net/cshift/api/transit/network/packet/IDynamicPacket.java
index 334d5f6..6d80b3b 100644
--- a/src/main/java/net/cshift/api/transit/network/packet/IDynamicPacket.java
+++ b/src/main/java/net/cshift/api/transit/network/packet/IDynamicPacket.java
@@ -1,14 +1,11 @@
package net.cshift.api.transit.network.packet;
-/** Interface describing a fluid packet.
+/** Interface describing a packet where the data can change as it's transferred.
+ *
+ * @param <D> The type parameter of the Type being transported
* @author Kyle Gunger
- *
- * @param <D> The data type (Object) that the packet transfers
*/
public interface IDynamicPacket<D> extends IStaticPacket<D>{
- /**Set the packet's data.
- *
- * @return <D> The packet's data
- */
- public void setData(D dat);
+ /** Set the packet's data. */
+ public void setData(Object dat);
}
diff --git a/src/main/java/net/cshift/api/transit/network/packet/IStaticPacket.java b/src/main/java/net/cshift/api/transit/network/packet/IStaticPacket.java
index ba1b17f..cdad90a 100644
--- a/src/main/java/net/cshift/api/transit/network/packet/IStaticPacket.java
+++ b/src/main/java/net/cshift/api/transit/network/packet/IStaticPacket.java
@@ -3,21 +3,21 @@ package net.cshift.api.transit.network.packet;
import net.cshift.api.transit.type.*;
/** Interface describing an unchanging packet.
- * @author Kyle Gunger
*
- * @param <D> The data type (Object) that the packet transfers.
+ * @param <D> The type parameter of the Type being transported
+ * @author Kyle Gunger
*/
public interface IStaticPacket<D>
{
/**Get the packet's data.
*
- * @return <D> The packet's data
+ * @return The packet's data
*/
- public D getData();
+ public Object getData();
/**Get the packet's type.
*
- * @return IType<<D>> The type of the packet
+ * @return IType<?> The type of the packet
*/
public Type<D> getType();
}
diff --git a/src/main/java/net/cshift/api/transit/network/packet/MetaDynamicPacket.java b/src/main/java/net/cshift/api/transit/network/packet/MetaDynamicPacket.java
deleted file mode 100644
index d382645..0000000
--- a/src/main/java/net/cshift/api/transit/network/packet/MetaDynamicPacket.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package net.cshift.api.transit.network.packet;
-
-import net.cshift.api.transit.type.Type;
-
-/** Static packet with extra data attached.
- * @author Kyle Gunger
- *
- * @param <D> The data type (Object) that the packet transfers
- * @param <M> The type of metadata
-*/
-public class MetaDynamicPacket<D, M> extends DynamicPacket<D>
-{
- private M metaData;
-
- /** Constructor
- *
- * @param dat The data to store
- * @param t The Type of the data
- * @param meta The metadata to store
- */
- public MetaDynamicPacket(D dat, Type<D> t, M meta)
- {
- super(dat, t);
- metaData = meta;
- }
-
- /** Get the metadata of the packet.
- *
- * @return The packet's metadata
- */
- public M getMetaData()
- {
- return metaData;
- }
-
- /** Set the metadata of the packet.
- *
- * @param meta The packet's new metadata
- */
- public void setMetaData(M meta)
- {
- metaData = meta;
- }
-}
diff --git a/src/main/java/net/cshift/api/transit/network/packet/MetaPacket.java b/src/main/java/net/cshift/api/transit/network/packet/MetaPacket.java
deleted file mode 100644
index aea1b83..0000000
--- a/src/main/java/net/cshift/api/transit/network/packet/MetaPacket.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package net.cshift.api.transit.network.packet;
-
-import net.cshift.api.transit.type.*;
-
-/** Static packet with extra data attached.
- * @author Kyle Gunger
- *
- * @param <D> The data type (Object) that the packet transfers
- * @param <M> The type of metadata
-*/
-public class MetaPacket<D, M> extends StaticPacket<D>
-{
- private M metaData;
-
- /** Constructor
- *
- * @param dat The data to store
- * @param t The Type of the data
- * @param meta The metadata to store
- */
- public MetaPacket(D dat, Type<D> t, M meta)
- {
- super(dat, t);
- metaData = meta;
- }
-
- /** Get the metadata of the packet.
- *
- * @return The packet's metadata
- */
- public M getMetaData()
- {
- return metaData;
- }
-}
diff --git a/src/main/java/net/cshift/api/transit/network/packet/StaticPacket.java b/src/main/java/net/cshift/api/transit/network/packet/StaticPacket.java
index 2c6a16a..5ffed26 100644
--- a/src/main/java/net/cshift/api/transit/network/packet/StaticPacket.java
+++ b/src/main/java/net/cshift/api/transit/network/packet/StaticPacket.java
@@ -9,7 +9,7 @@ import net.cshift.api.transit.type.*;
*/
public class StaticPacket<D> implements IStaticPacket<D>
{
- private D data;
+ private Object data;
private Type<D> type;
/** Constructor. Stores the given data and uses the given type.
@@ -17,14 +17,14 @@ public class StaticPacket<D> implements IStaticPacket<D>
* @param dat The packet's data
* @param t The packet's type
*/
- public StaticPacket(D dat, Type<D> t)
+ public StaticPacket(Object dat, Type<D> t)
{
data = dat;
type = t;
}
@Override
- public D getData()
+ public Object getData()
{
return data;
}