summaryrefslogtreecommitdiff
path: root/src/main/java/net/transit/network/swap/Provider.java
blob: 20656b8961f251c367a9c54167585f3ed40c6c9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package net.transit.network.swap;

import net.transit.network.packet.Packet;
import net.transit.network.system.Node;

/**
 * @author Kyle Gunger
 *
 * @param <T> The type of data provided (in IPacket<<T>> form)
 */
public interface Provider<T>
{
	/** Returns the INode this Provider is attached to. All Acceptors and Providers must be attached to an INode to function.
	 * 
	 * @return INode
	 */
	public Node getNode();
	
    /**
     * @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 Packet<T> provide();
    
    /**Retain the packet if the Acceptor did not accept the packet.
     * 
     * @param rejected The rejected packet
     */
    public void retain(Packet<T> rejected);
    
    /**
     * @return <b>True</b> if the Provider has an Acceptor 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(Acceptor<T> acceptor);
    
    /** Request that the Provider close it's connection to a Acceptor. The Provider may also shut itself down if no more Acceptors are attached.
     * 
     * @param acceptor The Acceptor 
     */
    public void shutdown(Acceptor<T> acceptor);
}