import java.net.Socket;
import java.net.SocketException;
import java.net.SocketTimeoutException;
-import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
_socketAddress.setAddress(actualSA.getAddress());
_socketAddress.setPort(actualSA.getPort());
}
- //log(Level.FINEST, _title, MessageFormat.format("Connection from {0}:{1}", _socketAddress.getAddress().getCanonicalHostName(), Integer.toString(_socketAddress.getPort())));
- // TODO: Complete this implementation
}
/**
boolean result = false;
try {
- //System.err.println("Before");
Socket connectionSocket = _serverSocket.accept();
- NetworkStream newStream = new NetworkStream(connectionSocket, _streamManager);
+ NetworkStream newStream = new NetworkStream(connectionSocket, _streamManager, LOGGER);
long userID = _streamManager.addStream(0, newStream);
// workaround to enable firing a ConnectionEstablishedEvent in process() on the owner thread
NetworkMessage temp = new NetworkMessage("triggerConnectionEstablishedEvent", null, new MessageNetworkStream(newStream));
publish(temp);
- log(Level.INFO, _title, MessageFormat.format("Incoming connection from {0}:{1}", connectionSocket.getInetAddress().getCanonicalHostName(), Integer.toString(connectionSocket.getPort())));
+ logp(Level.FINE, "Incoming connection from {0}", connectionSocket.getInetAddress().toString());
// add or update the last-seen time of the Sender host in the known services map
ServiceAddressMap.LastSeenHost host = new ServiceAddressMap.LastSeenHost((InetSocketAddress)connectionSocket.getRemoteSocketAddress());
this._serviceToHostMap.put(Long.toString(userID), host);
- log(Level.INFO, _title, MessageFormat.format("Added \"{0}\" to service map", userID));
- System.err.println("Added new TCP stream successfully");
+ logp(Level.INFO, "Added User ID \"{0}\" ({1}) to service map", String.valueOf(userID), host.toString());
+ result = true;
}
catch (SocketTimeoutException e) {
//Nothing to be done
}
- catch (IOException e) {
- // Nothing to be done
- System.err.println("Incoming connection caused exception...");
+ catch (IOException ex) {
+ logp(Level.SEVERE, "Incoming connection caused exception: {0}", ex.toString());
}
- return false;
+ return result;
}
private void fireConnectionEstablishedEvent(NetworkStream stream) {
@Override
protected void process(List<NetworkMessage> list) {
- System.err.println("process()");
for (NetworkMessage nm: list) {
MessageNetworkStream message = (MessageNetworkStream)nm.getMessage();
- System.err.println("ConnectionEstablished dispatched for " + message._stream._key);
fireConnectionEstablishedEvent(message._stream);
}