// This class is the source code whose specifications appear in the JSON file // net_connection_spec.json. package net; /** * Represents a connection on a communication channel. Allows sending messages * both coded as integers, or as text strings. */ public class Connection { /** * Creates a closed connection for the given communication channel. * * @param channel the communication channel, must be non-null */ public Connection(Channel channel) { ... } /** * Indicates whether this {@link Connection} is open. * * @returns true if the connection is open, false otherwise */ public boolean isOpen() { ... } /** * Establishes this {@link Connection} allowing messages to be sent * and received. * * @throws IllegalStateException if the connection is already open */ public void open() { ... } /** * Sends a text message on this {@link Connection}. * * @throws NullPointerException if message is null * @throws IllegalStateException if the connection is not open */ public void send(String message) { ... } /** * Sends a coded integer message on this {@link Connection} * * @param code the code, must be positive * @throws IllegalStateException if the connection is not open */ public void send(int coded) { ... } /** * Receives a coded integer message on this {@link Connection}. * * @return the received non-negative code value * @throws IllegalStateException if the connection is not open */ public int receive() { ... } }