// Path: ddp-client/src/main/java/io/advantageous/ddp/DDPMessageEndpoint.java
// public interface DDPMessageEndpoint {
//     void disconnect() throws IOException;
// 
//     void connect(String address) throws IOException, InterruptedException;
// 
//     <T> void registerHandler(Class<T> messageType, DDPMessageHandler.Phase phase, DDPMessageHandler<T> handler);
// 
//     <T> void registerHandler(Class<T> messageType, DDPMessageHandler<T> handler);
// 
//     void await() throws InterruptedException;
// 
//     void send(Object message) throws IOException;
// 
// }
// 
// Path: ddp-client/src/main/java/io/advantageous/ddp/subscription/message/NoSubscriptionMessage.java
// public class NoSubscriptionMessage {
// 
//     private String id;
// 
//     private DDPError error;
// 
//     public String getId() {
//         return id;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// 
//     public DDPError getError() {
//         return error;
//     }
// 
//     public void setError(DDPError error) {
//         this.error = error;
//     }
// }
// 
// Path: ddp-client/src/main/java/io/advantageous/ddp/subscription/message/ReadyMessage.java
// public class ReadyMessage {
// 
//     private String[] subs;
// 
//     public String[] getSubs() {
//         return subs;
//     }
// 
//     public void setSubs(String[] subs) {
//         this.subs = subs;
//     }
// }
// 
// Path: ddp-client/src/main/java/io/advantageous/ddp/subscription/message/SubscribeMessage.java
// public class SubscribeMessage {
// 
//     private String id;
// 
//     private String name;
// 
//     private Object[] params;
// 
//     public String getId() {
//         return id;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public Object[] getParams() {
//         return params;
//     }
// 
//     public void setParams(Object[] params) {
//         this.params = params;
//     }
// }
// 
// Path: ddp-client/src/main/java/io/advantageous/ddp/subscription/message/UnsubscribeMessage.java
// public class UnsubscribeMessage {
// 
//     private String id;
// 
//     public String getId() {
//         return id;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// }


import io.advantageous.ddp.DDPMessageEndpoint;
import io.advantageous.ddp.subscription.message.NoSubscriptionMessage;
import io.advantageous.ddp.subscription.message.ReadyMessage;
import io.advantageous.ddp.subscription.message.SubscribeMessage;
import io.advantageous.ddp.subscription.message.UnsubscribeMessage;
import javax.inject.Inject;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
        });
        messageEndpoint.registerHandler(NoSubscriptionMessage.class, message -> {
            final Subscription.Callback callback = this.callbackMap.get(message.getId());
            if (callback != null) {
                callback.onFailure(message.getId(), message.getError());
                this.callbackMap.remove(message.getId());
            }
        });

    }

    @Override
    public void subscribe(final Subscription subscription) throws IOException {
        final Long subscriptionId = SEQUENCE.getAndIncrement();
        final String id = subscriptionId.toString();
        final Subscription.Callback callback = subscription.getCallback();
        if (callback != null) {
            this.callbackMap.put(id, subscription.getCallback());
        }
        this.objectConverter.register(subscription.getSubscriptionName(), subscription.getClazz());
        final SubscribeMessage message = new SubscribeMessage();
        message.setId(id);
        message.setName(subscription.getSubscriptionName());
        message.setParams(subscription.getParams());
        this.messageEndpoint.send(message);
    }

    @Override
    public void unsubscribe(final String subscriptionId) throws IOException {
        this.callbackMap.remove(subscriptionId);
// Path: ddp-client/src/main/java/io/advantageous/ddp/DDPMessageEndpoint.java
// public interface DDPMessageEndpoint {
//     void disconnect() throws IOException;
// 
//     void connect(String address) throws IOException, InterruptedException;
// 
//     <T> void registerHandler(Class<T> messageType, DDPMessageHandler.Phase phase, DDPMessageHandler<T> handler);
// 
//     <T> void registerHandler(Class<T> messageType, DDPMessageHandler<T> handler);
// 
//     void await() throws InterruptedException;
// 
//     void send(Object message) throws IOException;
// 
// }
// 
// Path: ddp-client/src/main/java/io/advantageous/ddp/subscription/message/NoSubscriptionMessage.java
// public class NoSubscriptionMessage {
// 
//     private String id;
// 
//     private DDPError error;
// 
//     public String getId() {
//         return id;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// 
//     public DDPError getError() {
//         return error;
//     }
// 
//     public void setError(DDPError error) {
//         this.error = error;
//     }
// }
// 
// Path: ddp-client/src/main/java/io/advantageous/ddp/subscription/message/ReadyMessage.java
// public class ReadyMessage {
// 
//     private String[] subs;
// 
//     public String[] getSubs() {
//         return subs;
//     }
// 
//     public void setSubs(String[] subs) {
//         this.subs = subs;
//     }
// }
// 
// Path: ddp-client/src/main/java/io/advantageous/ddp/subscription/message/SubscribeMessage.java
// public class SubscribeMessage {
// 
//     private String id;
// 
//     private String name;
// 
//     private Object[] params;
// 
//     public String getId() {
//         return id;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public Object[] getParams() {
//         return params;
//     }
// 
//     public void setParams(Object[] params) {
//         this.params = params;
//     }
// }
// 
// Path: ddp-client/src/main/java/io/advantageous/ddp/subscription/message/UnsubscribeMessage.java
// public class UnsubscribeMessage {
// 
//     private String id;
// 
//     public String getId() {
//         return id;
//     }
// 
//     public void setId(String id) {
//         this.id = id;
//     }
// }


// Path: ddp-client/src/main/java/io/advantageous/ddp/subscription/BaseSubscriptionAdapter.java
import io.advantageous.ddp.DDPMessageEndpoint;
import io.advantageous.ddp.subscription.message.NoSubscriptionMessage;
import io.advantageous.ddp.subscription.message.ReadyMessage;
import io.advantageous.ddp.subscription.message.SubscribeMessage;
import io.advantageous.ddp.subscription.message.UnsubscribeMessage;
import javax.inject.Inject;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;

        });
        messageEndpoint.registerHandler(NoSubscriptionMessage.class, message -> {
            final Subscription.Callback callback = this.callbackMap.get(message.getId());
            if (callback != null) {
                callback.onFailure(message.getId(), message.getError());
                this.callbackMap.remove(message.getId());
            }
        });

    }

    @Override
    public void subscribe(final Subscription subscription) throws IOException {
        final Long subscriptionId = SEQUENCE.getAndIncrement();
        final String id = subscriptionId.toString();
        final Subscription.Callback callback = subscription.getCallback();
        if (callback != null) {
            this.callbackMap.put(id, subscription.getCallback());
        }
        this.objectConverter.register(subscription.getSubscriptionName(), subscription.getClazz());
        final SubscribeMessage message = new SubscribeMessage();
        message.setId(id);
        message.setName(subscription.getSubscriptionName());
        message.setParams(subscription.getParams());
        this.messageEndpoint.send(message);
    }

    @Override
    public void unsubscribe(final String subscriptionId) throws IOException {
        this.callbackMap.remove(subscriptionId);
        final UnsubscribeMessage message = new UnsubscribeMessage();