// Path: src/main/java/org/msgpack/rpc/Request.java
// public class Request implements Callback<Object> {
//     private MessageSendable channel; // TODO #SF synchronized?
//     private int msgid;
//     private String method;
//     private Value args;
// 
//     public Request(MessageSendable channel, int msgid, String method, Value args) {
//         this.channel = channel;
//         this.msgid = msgid;
//         this.method = method;
//         this.args = args;
//     }
// 
//     public Request(String method, Value args) {
//         this.channel = null;
//         this.msgid = 0;
//         this.method = method;
//         this.args = args;
//     }
// 
//     public String getMethodName() {
//         return method;
//     }
// 
//     public Value getArguments() {
//         return args;
//     }
// 
//     public int getMessageID() {
//         return msgid;
//     }
// 
//     public void sendResult(Object result) {
//         sendResponse(result, null);
//     }
// 
//     public void sendError(Object error) {
//         sendResponse(null, error);
//     }
// 
//     public void sendError(Object error, Object data) {
//         sendResponse(data, error);
//     }
// 
//     public synchronized void sendResponse(Object result, Object error) {
//         if (channel == null) {
//             return;
//         }
//         ResponseMessage msg = new ResponseMessage(msgid, error, result);
//         channel.sendMessage(msg);
//         channel = null;
//     }
// }
// 
// Path: src/main/java/org/msgpack/rpc/reflect/ReflectionInvokerBuilder.java
// static abstract class ReflectionArgumentEntry extends ArgumentEntry {
// 	ReflectionArgumentEntry(ArgumentEntry e) {
// 		super(e);
// 	}
// 
// 	public abstract void convert(Object[] params, Value obj) throws MessageTypeException;
// 
// 	public void setNull(Object[] params) {
// 		params[getIndex()] = null;
// 	}
// }


import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import javassist.CannotCompileException;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtConstructor;
import javassist.CtMethod;
import javassist.CtNewConstructor;
import javassist.CtNewMethod;
import javassist.LoaderClassPath;
import javassist.NotFoundException;
import org.msgpack.MessagePack;
import org.msgpack.type.Value;
import org.msgpack.MessageTypeException;
import org.msgpack.template.Template;
import org.msgpack.rpc.Request;
import org.msgpack.rpc.reflect.ReflectionInvokerBuilder.ReflectionArgumentEntry;
import org.msgpack.template.TemplateRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//
// MessagePack-RPC for Java
//
// Copyright (C) 2010 FURUHASHI Sadayuki
//
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//
//        http://www.apache.org/licenses/LICENSE-2.0
//
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.
//
package org.msgpack.rpc.reflect;




public class JavassistInvokerBuilder extends InvokerBuilder {
    private static Logger LOG = LoggerFactory.getLogger(JavassistInvokerBuilder.class);


	protected abstract static class AbstractInvoker implements Invoker {
        protected Method method;
        protected int parameterLength;
        protected ReflectionArgumentEntry[] entries;
        protected int minimumArrayLength;
        boolean async;

        public AbstractInvoker(Method method, ReflectionArgumentEntry[] entries, boolean async) {
            this.method = method;
            this.parameterLength = method.getParameterTypes().length;
            this.entries = entries;
            this.async = async;
            this.minimumArrayLength = 0;
            for(int i=0; i < entries.length; i++) {
                ReflectionArgumentEntry e = entries[i];
                if(!e.isOptional()){//e.isRequired() || e.isNullable()) {
                    this.minimumArrayLength = i+1;
                }
            }
        }

// Path: src/main/java/org/msgpack/rpc/Request.java
// public class Request implements Callback<Object> {
//     private MessageSendable channel; // TODO #SF synchronized?
//     private int msgid;
//     private String method;
//     private Value args;
// 
//     public Request(MessageSendable channel, int msgid, String method, Value args) {
//         this.channel = channel;
//         this.msgid = msgid;
//         this.method = method;
//         this.args = args;
//     }
// 
//     public Request(String method, Value args) {
//         this.channel = null;
//         this.msgid = 0;
//         this.method = method;
//         this.args = args;
//     }
// 
//     public String getMethodName() {
//         return method;
//     }
// 
//     public Value getArguments() {
//         return args;
//     }
// 
//     public int getMessageID() {
//         return msgid;
//     }
// 
//     public void sendResult(Object result) {
//         sendResponse(result, null);
//     }
// 
//     public void sendError(Object error) {
//         sendResponse(null, error);
//     }
// 
//     public void sendError(Object error, Object data) {
//         sendResponse(data, error);
//     }
// 
//     public synchronized void sendResponse(Object result, Object error) {
//         if (channel == null) {
//             return;
//         }
//         ResponseMessage msg = new ResponseMessage(msgid, error, result);
//         channel.sendMessage(msg);
//         channel = null;
//     }
// }
// 
// Path: src/main/java/org/msgpack/rpc/reflect/ReflectionInvokerBuilder.java
// static abstract class ReflectionArgumentEntry extends ArgumentEntry {
// 	ReflectionArgumentEntry(ArgumentEntry e) {
// 		super(e);
// 	}
// 
// 	public abstract void convert(Object[] params, Value obj) throws MessageTypeException;
// 
// 	public void setNull(Object[] params) {
// 		params[getIndex()] = null;
// 	}
// }


// Path: src/main/java/org/msgpack/rpc/reflect/JavassistInvokerBuilder.java
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import javassist.CannotCompileException;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtConstructor;
import javassist.CtMethod;
import javassist.CtNewConstructor;
import javassist.CtNewMethod;
import javassist.LoaderClassPath;
import javassist.NotFoundException;
import org.msgpack.MessagePack;
import org.msgpack.type.Value;
import org.msgpack.MessageTypeException;
import org.msgpack.template.Template;
import org.msgpack.rpc.Request;
import org.msgpack.rpc.reflect.ReflectionInvokerBuilder.ReflectionArgumentEntry;
import org.msgpack.template.TemplateRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

//
// MessagePack-RPC for Java
//
// Copyright (C) 2010 FURUHASHI Sadayuki
//
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//
//        http://www.apache.org/licenses/LICENSE-2.0
//
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.
//
package org.msgpack.rpc.reflect;




public class JavassistInvokerBuilder extends InvokerBuilder {
    private static Logger LOG = LoggerFactory.getLogger(JavassistInvokerBuilder.class);


	protected abstract static class AbstractInvoker implements Invoker {
        protected Method method;
        protected int parameterLength;
        protected ReflectionArgumentEntry[] entries;
        protected int minimumArrayLength;
        boolean async;

        public AbstractInvoker(Method method, ReflectionArgumentEntry[] entries, boolean async) {
            this.method = method;
            this.parameterLength = method.getParameterTypes().length;
            this.entries = entries;
            this.async = async;
            this.minimumArrayLength = 0;
            for(int i=0; i < entries.length; i++) {
                ReflectionArgumentEntry e = entries[i];
                if(!e.isOptional()){//e.isRequired() || e.isNullable()) {
                    this.minimumArrayLength = i+1;
                }
            }
        }

        public void invoke(Object target, Request request) throws Exception {