package com.b5m.msgpack;

import java.net.UnknownHostException;

import org.msgpack.rpc.Client;
import org.msgpack.rpc.loop.EventLoop;

import com.b5m.conf.Configuration;

public class RpcClient {
	private static RpcClient rpcClient = null;

	public static synchronized RpcClient getInstance()
			throws UnknownHostException {
		if (null == rpcClient) {
			rpcClient = new RpcClient();
		}
		return rpcClient;
	}

	private final RPCInterface iface;
	private final Client client;

	static interface RPCInterface {
		SplitTitleResponse spliteTitle(SplitTitleRequest request);

		ClusterInfoResponse getClusteringInfos(ClusterInfoRequest req);

		void updateTopNCluster(PriorityQueue queue);

	}

	public RpcClient() throws UnknownHostException {
		Configuration conf = Configuration.getInstance();
		EventLoop loop = EventLoop.defaultEventLoop();
		client = new Client(conf.getMsgpackAddress().split(",")[0], conf.getMsgpackPort(),
				loop);
		client.setRequestTimeout(100000);

		iface = client.proxy(RPCInterface.class);
	}

	public void close() {
		client.close();
	}

	public SplitTitleResponse spliteTitle(SplitTitleRequest request) {
		return iface.spliteTitle(request);
	}

	public ClusterInfoResponse getClusterInfos(ClusterInfoRequest req) {
		return iface.getClusteringInfos(req);
	}

	public void updateTopNCluster(PriorityQueue queue) {
		iface.updateTopNCluster(queue);
	}

}

@@ -638,57 +638,8 @@
 q);%0A
-%0A%09%09void updateTopNCluster(PriorityQueue queue);%0A%0A
 %09%7D%0A%0A
@@ -1241,99 +1241,6 @@
 %0A%09%7D%0A
-%0A%09public void updateTopNCluster(PriorityQueue queue) %7B%0A%09%09iface.updateTopNCluster(queue);%0A%09%7D%0A%0A
 %7D%0A

remove write operation from RpcClient