// Path: src/main/java/com/mpush/util/thread/EventLock.java
// public final class EventLock {
//     private final ReentrantLock lock;
//     private final Condition cond;
// 
//     public EventLock() {
//         lock = new ReentrantLock();
//         cond = lock.newCondition();
//     }
// 
//     public void lock() {
//         lock.lock();
//     }
// 
//     public void unlock() {
//         lock.unlock();
//     }
// 
//     public void signal() {
//         cond.signal();
//     }
// 
//     public void signalAll() {
//         cond.signalAll();
//     }
// 
//     public void broadcast() {
//         lock.lock();
//         cond.signalAll();
//         lock.unlock();
//     }
// 
//     public boolean await(long timeout) {
//         lock.lock();
//         try {
//             cond.awaitNanos(TimeUnit.MILLISECONDS.toNanos(timeout));
//         } catch (InterruptedException e) {
//             return true;
//         } finally {
//             lock.unlock();
//         }
//         return false;
//     }
// 
//     public boolean await() {
//         lock.lock();
//         try {
//             cond.await();
//         } catch (InterruptedException e) {
//             return true;
//         } finally {
//             lock.unlock();
//         }
//         return false;
//     }
// 
//     public ReentrantLock getLock() {
//         return lock;
//     }
// 
//     public Condition getCond() {
//         return cond;
//     }
// }
// 
// Path: src/main/java/com/mpush/util/thread/ExecutorManager.java
// public final class ExecutorManager {
//     public static final String THREAD_NAME_PREFIX = "mp-client-";
//     public static final String WRITE_THREAD_NAME = THREAD_NAME_PREFIX + "write-t";
//     public static final String READ_THREAD_NAME = THREAD_NAME_PREFIX + "read-t";
//     public static final String DISPATCH_THREAD_NAME = THREAD_NAME_PREFIX + "dispatch-t";
//     public static final String START_THREAD_NAME = THREAD_NAME_PREFIX + "start-t";
//     public static final String TIMER_THREAD_NAME = THREAD_NAME_PREFIX + "timer-t";
//     public static final ExecutorManager INSTANCE = new ExecutorManager();
//     private ThreadPoolExecutor writeThread;
//     private ThreadPoolExecutor dispatchThread;
//     private ScheduledExecutorService timerThread;
// 
//     public ThreadPoolExecutor getWriteThread() {
//         if (writeThread == null || writeThread.isShutdown()) {
//             writeThread = new ThreadPoolExecutor(1, 1,
//                     0L, TimeUnit.MILLISECONDS,
//                     new LinkedBlockingQueue<Runnable>(100),
//                     new NamedThreadFactory(WRITE_THREAD_NAME),
//                     new RejectedHandler());
//         }
//         return writeThread;
//     }
// 
//     public ThreadPoolExecutor getDispatchThread() {
//         if (dispatchThread == null || dispatchThread.isShutdown()) {
//             dispatchThread = new ThreadPoolExecutor(2, 4,
//                     1L, TimeUnit.SECONDS,
//                     new LinkedBlockingQueue<Runnable>(100),
//                     new NamedThreadFactory(DISPATCH_THREAD_NAME),
//                     new RejectedHandler());
//         }
//         return dispatchThread;
//     }
// 
//     public ScheduledExecutorService getTimerThread() {
//         if (timerThread == null || timerThread.isShutdown()) {
//             timerThread = new ScheduledThreadPoolExecutor(1,
//                     new NamedThreadFactory(TIMER_THREAD_NAME),
//                     new RejectedHandler());
//         }
//         return timerThread;
//     }
// 
//     public synchronized void shutdown() {
//         if (writeThread != null) {
//             writeThread.shutdownNow();
//             writeThread = null;
//         }
//         if (dispatchThread != null) {
//             dispatchThread.shutdownNow();
//             dispatchThread = null;
//         }
//         if (timerThread != null) {
//             timerThread.shutdownNow();
//             timerThread = null;
//         }
//     }
// 
//     public static boolean isMPThread() {
//         return Thread.currentThread().getName().startsWith(THREAD_NAME_PREFIX);
//     }
// 
//     private static class RejectedHandler implements RejectedExecutionHandler {
// 
//         @Override
//         public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
//             ClientConfig.I.getLogger().w("a task was rejected r=%s", r);
//         }
//     }
// }


import java.util.concurrent.Callable;
import com.mpush.util.thread.EventLock;
import com.mpush.util.thread.ExecutorManager;
/*
 * (C) Copyright 2015-2016 the original author or authors.
 *
 * 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.
 *
 * Contributors:
 *     ohun@live.cn (夜色)
 */

package com.mpush.client;




/**
 * Created by yxx on 2016/6/9.
 *
 * @author ohun@live.cn (夜色)
 */
public class ConnectThread extends Thread {
    private volatile Callable<Boolean> runningTask;
    private volatile boolean runningFlag = true;
    private final EventLock connLock;
// Path: src/main/java/com/mpush/util/thread/EventLock.java
// public final class EventLock {
//     private final ReentrantLock lock;
//     private final Condition cond;
// 
//     public EventLock() {
//         lock = new ReentrantLock();
//         cond = lock.newCondition();
//     }
// 
//     public void lock() {
//         lock.lock();
//     }
// 
//     public void unlock() {
//         lock.unlock();
//     }
// 
//     public void signal() {
//         cond.signal();
//     }
// 
//     public void signalAll() {
//         cond.signalAll();
//     }
// 
//     public void broadcast() {
//         lock.lock();
//         cond.signalAll();
//         lock.unlock();
//     }
// 
//     public boolean await(long timeout) {
//         lock.lock();
//         try {
//             cond.awaitNanos(TimeUnit.MILLISECONDS.toNanos(timeout));
//         } catch (InterruptedException e) {
//             return true;
//         } finally {
//             lock.unlock();
//         }
//         return false;
//     }
// 
//     public boolean await() {
//         lock.lock();
//         try {
//             cond.await();
//         } catch (InterruptedException e) {
//             return true;
//         } finally {
//             lock.unlock();
//         }
//         return false;
//     }
// 
//     public ReentrantLock getLock() {
//         return lock;
//     }
// 
//     public Condition getCond() {
//         return cond;
//     }
// }
// 
// Path: src/main/java/com/mpush/util/thread/ExecutorManager.java
// public final class ExecutorManager {
//     public static final String THREAD_NAME_PREFIX = "mp-client-";
//     public static final String WRITE_THREAD_NAME = THREAD_NAME_PREFIX + "write-t";
//     public static final String READ_THREAD_NAME = THREAD_NAME_PREFIX + "read-t";
//     public static final String DISPATCH_THREAD_NAME = THREAD_NAME_PREFIX + "dispatch-t";
//     public static final String START_THREAD_NAME = THREAD_NAME_PREFIX + "start-t";
//     public static final String TIMER_THREAD_NAME = THREAD_NAME_PREFIX + "timer-t";
//     public static final ExecutorManager INSTANCE = new ExecutorManager();
//     private ThreadPoolExecutor writeThread;
//     private ThreadPoolExecutor dispatchThread;
//     private ScheduledExecutorService timerThread;
// 
//     public ThreadPoolExecutor getWriteThread() {
//         if (writeThread == null || writeThread.isShutdown()) {
//             writeThread = new ThreadPoolExecutor(1, 1,
//                     0L, TimeUnit.MILLISECONDS,
//                     new LinkedBlockingQueue<Runnable>(100),
//                     new NamedThreadFactory(WRITE_THREAD_NAME),
//                     new RejectedHandler());
//         }
//         return writeThread;
//     }
// 
//     public ThreadPoolExecutor getDispatchThread() {
//         if (dispatchThread == null || dispatchThread.isShutdown()) {
//             dispatchThread = new ThreadPoolExecutor(2, 4,
//                     1L, TimeUnit.SECONDS,
//                     new LinkedBlockingQueue<Runnable>(100),
//                     new NamedThreadFactory(DISPATCH_THREAD_NAME),
//                     new RejectedHandler());
//         }
//         return dispatchThread;
//     }
// 
//     public ScheduledExecutorService getTimerThread() {
//         if (timerThread == null || timerThread.isShutdown()) {
//             timerThread = new ScheduledThreadPoolExecutor(1,
//                     new NamedThreadFactory(TIMER_THREAD_NAME),
//                     new RejectedHandler());
//         }
//         return timerThread;
//     }
// 
//     public synchronized void shutdown() {
//         if (writeThread != null) {
//             writeThread.shutdownNow();
//             writeThread = null;
//         }
//         if (dispatchThread != null) {
//             dispatchThread.shutdownNow();
//             dispatchThread = null;
//         }
//         if (timerThread != null) {
//             timerThread.shutdownNow();
//             timerThread = null;
//         }
//     }
// 
//     public static boolean isMPThread() {
//         return Thread.currentThread().getName().startsWith(THREAD_NAME_PREFIX);
//     }
// 
//     private static class RejectedHandler implements RejectedExecutionHandler {
// 
//         @Override
//         public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
//             ClientConfig.I.getLogger().w("a task was rejected r=%s", r);
//         }
//     }
// }


// Path: src/main/java/com/mpush/client/ConnectThread.java
import java.util.concurrent.Callable;
import com.mpush.util.thread.EventLock;
import com.mpush.util.thread.ExecutorManager;

/*
 * (C) Copyright 2015-2016 the original author or authors.
 *
 * 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.
 *
 * Contributors:
 *     ohun@live.cn (夜色)
 */

package com.mpush.client;




/**
 * Created by yxx on 2016/6/9.
 *
 * @author ohun@live.cn (夜色)
 */
public class ConnectThread extends Thread {
    private volatile Callable<Boolean> runningTask;
    private volatile boolean runningFlag = true;
    private final EventLock connLock;
    public ConnectThread(EventLock connLock) {