// 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;
/*
 * Copyright (C) 2014. Geoffrey Chandler.
 *
 * 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 io.advantageous.ddp.subscription;



/**
 * Base class for handling DDP subscriptions.
 *
 * @author geoffc@gmail.com
 * @since 1/21/14 at 3:55 PM.
 */
public class BaseSubscriptionAdapter implements SubscriptionAdapter {

    private static final AtomicLong SEQUENCE = new AtomicLong(0);

    protected final Map<String, Subscription.Callback> callbackMap = new ConcurrentHashMap<>();

    protected final ObjectConverter objectConverter;

    protected final DDPMessageEndpoint messageEndpoint;

    @Inject
    public BaseSubscriptionAdapter(final DDPMessageEndpoint messageEndpoint,
                                   final ObjectConverter objectConverter) {

        this.objectConverter = objectConverter;
        this.messageEndpoint = messageEndpoint;

// 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;

/*
 * Copyright (C) 2014. Geoffrey Chandler.
 *
 * 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 io.advantageous.ddp.subscription;



/**
 * Base class for handling DDP subscriptions.
 *
 * @author geoffc@gmail.com
 * @since 1/21/14 at 3:55 PM.
 */
public class BaseSubscriptionAdapter implements SubscriptionAdapter {

    private static final AtomicLong SEQUENCE = new AtomicLong(0);

    protected final Map<String, Subscription.Callback> callbackMap = new ConcurrentHashMap<>();

    protected final ObjectConverter objectConverter;

    protected final DDPMessageEndpoint messageEndpoint;

    @Inject
    public BaseSubscriptionAdapter(final DDPMessageEndpoint messageEndpoint,
                                   final ObjectConverter objectConverter) {

        this.objectConverter = objectConverter;
        this.messageEndpoint = messageEndpoint;

        messageEndpoint.registerHandler(ReadyMessage.class, message -> {