// Path: src/wtf/socket/event/WTFSocketEventsType.java
// public enum WTFSocketEventsType {
//     /**
//      * 客户端断开连接时触发
//      */
//     Disconnect,
//     /**
//      * 有新客户端连接时触发
//      */
//     Connect,
//     /**
//      * 收到新消息时触发
//      * 在安全检查之前
//      */
//     OnReceiveData,
//     /**
//      * 发送消息前触发
//      * 在安全检查之前
//      */
//     BeforeSendData,
//     /**
//      * 服务器启动时触发
//      */
//     ServerStarted
// }
// 
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
// 
// 
//     public WTFSocketException(String msg) {
//         super(msg);
//     }
// 
//     public abstract int getErrCode();
// 
// }


import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import wtf.socket.event.WTFSocketEventsType;
import wtf.socket.exception.WTFSocketException;
import java.util.concurrent.TimeUnit;
package wtf.socket.routing.item;



/**
 * 临时客户端
 * <p>
 * Created by ZFly on 2017/4/23.
 */
@Component
@Scope("prototype")
public class WTFSocketRoutingTmpItem extends WTFSocketRoutingItem {

    /**
     * 过期时间
     */
    private long expires = TimeUnit.MINUTES.toMillis(1);

    public void setExpires(int duration, TimeUnit unit) {
        expires = System.currentTimeMillis() + unit.toMillis(duration);
    }

    public boolean isExpires() {
        return expires < System.currentTimeMillis();
    }

    public void shiftToFormal() throws WTFSocketException{
        getContext().getRouting().getTmpMap().remove(this);
        final WTFSocketRoutingFormalItem newFormal = new WTFSocketRoutingFormalItem();
        BeanUtils.copyProperties(this, newFormal);
        getContext().getRouting().getFormalMap().add(newFormal);
    }

    public void shiftToDebug() throws WTFSocketException {
        getContext().getRouting().getTmpMap().remove(this);
        final WTFSocketRoutingDebugItem newDebug = new WTFSocketRoutingDebugItem();
// Path: src/wtf/socket/event/WTFSocketEventsType.java
// public enum WTFSocketEventsType {
//     /**
//      * 客户端断开连接时触发
//      */
//     Disconnect,
//     /**
//      * 有新客户端连接时触发
//      */
//     Connect,
//     /**
//      * 收到新消息时触发
//      * 在安全检查之前
//      */
//     OnReceiveData,
//     /**
//      * 发送消息前触发
//      * 在安全检查之前
//      */
//     BeforeSendData,
//     /**
//      * 服务器启动时触发
//      */
//     ServerStarted
// }
// 
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
// 
// 
//     public WTFSocketException(String msg) {
//         super(msg);
//     }
// 
//     public abstract int getErrCode();
// 
// }


// Path: src/wtf/socket/routing/item/WTFSocketRoutingTmpItem.java
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import wtf.socket.event.WTFSocketEventsType;
import wtf.socket.exception.WTFSocketException;
import java.util.concurrent.TimeUnit;

package wtf.socket.routing.item;



/**
 * 临时客户端
 * <p>
 * Created by ZFly on 2017/4/23.
 */
@Component
@Scope("prototype")
public class WTFSocketRoutingTmpItem extends WTFSocketRoutingItem {

    /**
     * 过期时间
     */
    private long expires = TimeUnit.MINUTES.toMillis(1);

    public void setExpires(int duration, TimeUnit unit) {
        expires = System.currentTimeMillis() + unit.toMillis(duration);
    }

    public boolean isExpires() {
        return expires < System.currentTimeMillis();
    }

    public void shiftToFormal() throws WTFSocketException{
        getContext().getRouting().getTmpMap().remove(this);
        final WTFSocketRoutingFormalItem newFormal = new WTFSocketRoutingFormalItem();
        BeanUtils.copyProperties(this, newFormal);
        getContext().getRouting().getFormalMap().add(newFormal);
    }

    public void shiftToDebug() throws WTFSocketException {
        getContext().getRouting().getTmpMap().remove(this);
        final WTFSocketRoutingDebugItem newDebug = new WTFSocketRoutingDebugItem();
        BeanUtils.copyProperties(this, newDebug);