package net.apexes.wsonrpc.server;

import java.nio.ByteBuffer;

import javax.websocket.CloseReason;
import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;

import net.apexes.wsonrpc.ExceptionProcessor;
import net.apexes.wsonrpc.WsonrpcConfig;
import net.apexes.wsonrpc.internal.WebSocketSessionAdapter;

/**
 * 
 * @author <a href=mailto:hedyn@foxmail.com>HeDYn</a>
 *
 */
public abstract class WsonrpcServerEndpoint {

    protected final WsonrpcServerProxy proxy;

    protected WsonrpcServerEndpoint(WsonrpcConfig config) {
        proxy = new WsonrpcServerProxy(config);
    }

    public WsonrpcServerEndpoint addService(String name, Object handler) {
        proxy.register(name, handler);
        return this;
    }

    public void setExceptionProcessor(ExceptionProcessor processor) {
        proxy.setExceptionProcessor(processor);
    }

    @OnOpen
    public void onOpen(Session session) {
        proxy.onOpen(new WebSocketSessionAdapter(session));
    }

    @OnClose
    public void onClose(Session session, CloseReason closeReason) {
        proxy.onClose(session.getId());
    }

    @OnMessage
    public void onMessage(Session session, ByteBuffer buffer) {
        proxy.onMessage(session.getId(), buffer);
    }

}

@@ -692,40 +692,21 @@
 lic 
-WsonrpcServerEndpoint addService
+void register
 (Str
@@ -782,23 +782,92 @@
     
+%7D%0D%0A
     
-return this
+%0D%0A    public void register(Object handler) %7B%0D%0A        proxy.register(handler)
 ;%0D%0A 

删除addService(String,Object)方法，改用ServiceRegistry