mirror of
https://github.com/ChronosX88/KademliaDHT.git
synced 2024-12-22 15:51:46 +00:00
Added a message factory interface
This commit is contained in:
parent
b594b91adf
commit
720b062646
37
src/kademlia/message/KademliaMessageFactory.java
Normal file
37
src/kademlia/message/KademliaMessageFactory.java
Normal file
@ -0,0 +1,37 @@
|
||||
package kademlia.message;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import kademlia.core.KadServer;
|
||||
|
||||
/**
|
||||
* A factory that handles creating messages and receivers
|
||||
*
|
||||
* @author Joshua Kissoon
|
||||
* @since 20140523
|
||||
*/
|
||||
public interface KademliaMessageFactory
|
||||
{
|
||||
|
||||
/**
|
||||
* Method that creates a message based on the code and input stream
|
||||
*
|
||||
* @param code The message code
|
||||
* @param in An input stream with the message data
|
||||
*
|
||||
* @return A message
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
public Message createMessage(byte code, DataInputStream in) throws IOException;
|
||||
|
||||
/**
|
||||
* Method that returns a receiver to handle a specific type of message
|
||||
*
|
||||
* @param code The message code
|
||||
* @param server
|
||||
*
|
||||
* @return A receiver
|
||||
*/
|
||||
public Receiver createReceiver(byte code, KadServer server);
|
||||
}
|
@ -13,7 +13,7 @@ import kademlia.dht.DHT;
|
||||
* @author Joshua Kissoon
|
||||
* @since 20140202
|
||||
*/
|
||||
public class MessageFactory
|
||||
public class MessageFactory implements KademliaMessageFactory
|
||||
{
|
||||
|
||||
private final KademliaNode localNode;
|
||||
@ -27,6 +27,7 @@ public class MessageFactory
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message createMessage(byte code, DataInputStream in) throws IOException
|
||||
{
|
||||
switch (code)
|
||||
@ -54,6 +55,7 @@ public class MessageFactory
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Receiver createReceiver(byte code, KadServer server)
|
||||
{
|
||||
switch (code)
|
||||
|
Loading…
Reference in New Issue
Block a user