Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package net.scattersphere.client;
 
 
 import java.util.Map;

This is a class that caches net.scattersphere.api.StreamClient connections. Created by kenji on 2/14/15.
public class StreamClientCache {
	private static final StreamClientCache instance = new StreamClientCache();
	private final Map<StringStreamClientclients;
	private StreamClientCache() {
		 = new HashMap<>();
	}

    
Returns the singleton instance of the StreamClientCache object.

Returns:
StreamClientCache object.
	public static StreamClientCache instance() {
		return ;
	}

    
Opens a stream, connecting to localhost, pulling in stream data for the specified ID.

Parameters:
streamId The stream ID to retrieve.
out The active java.io.PrintWriter object.
	public void openStream(String streamIdPrintWriter out) {
		if (.get(streamId) != null) {
			out.println("Already subscribed to stream ID " + streamId);
			return;
		}
		StreamClient streamClient = new StreamClient();
		streamClient.onConnect(x -> {
			streamClient.openStream(streamIdstreamId);
			out.println("[" + streamId + "] Connected to " + x);
			out.flush();
		});
		streamClient.onDisconnect(x -> {
			out.println("[" + streamId + "] Disconnected from " + x);
			out.flush();
			.remove(streamId);
		});
		streamClient.onStream((namedata) -> {
			out.println("[" + name + "] data=" + new String(data));
			out.flush();
		});
		streamClient.addClient(streamId"localhost");
		.put(streamIdstreamClient);
	}

    
Closes a stream connection.

Parameters:
streamId The stream ID to disconnect from.
out The currently active java.io.PrintWriter object.
	public void closeStream(String streamIdPrintWriter out) {
		if (.get(streamId) == null) {
			out.println("Not subscribed to stream ID " + streamId);
			out.flush();
			return;
		}
		StreamClient streamClient = .get(streamId);
		streamClient.closeStream(streamIdstreamId);
		out.println("Unsubscribed from stream ID " + streamId);
		out.flush();
	}
New to GrepCode? Check out our FAQ X