// Path: core/src/main/java/org/nesty/core/server/rest/URLResource.java
// public class URLResource {
// 
//     // variable flag
//     public static final char VARIABLE = '{';
//     // resource identifier
//     private URLResourceIdentifier identifier;
// 
//     private URLResource() {
// 
//     }
// 
//     public static URLResource fromHttp(String url, RequestMethod requestMethod) {
//         URLResource resource = new URLResource();
//         resource.identifier = URLResourceIdentifier.analyse(url);
//         resource.identifier.requestMethod = requestMethod;
//         return resource;
//     }
// 
//     public RequestMethod requestMethod() {
//         return identifier.requestMethod;
//     }
// 
//     public List<String> fragments() {
//         return identifier.fragments;
//     }
// 
//     @Override
//     public String toString() {
//         return identifier.toString();
//     }
// 
//     @Override
//     public int hashCode() {
//         return identifier.hashCode();
//     }
// 
//     @Override
//     public boolean equals(Object other) {
//         return !(other == null || !(other instanceof URLResource)) && identifier.equals(((URLResource) other).identifier);
//     }
// 
//     /**
//      * URLResource uniqu identifier member. used for URLResource
//      * equals and hashcode id
//      */
//     static class URLResourceIdentifier {
//         protected List<String> fragments = new ArrayList<>(64);
//         protected RequestMethod requestMethod;
// 
//         public static URLResourceIdentifier analyse(String url) {
//             url = HttpUtils.truncateUrl(url);
//             URLResourceIdentifier identifier = new URLResourceIdentifier();
//             for (String s : Splitter.on('/').trimResults().omitEmptyStrings().split(url))
//                 identifier.fragments.add(s);
//             return identifier;
//         }
// 
//         @Override
//         public boolean equals(Object object) {
//             if (object == null || !(object instanceof URLResourceIdentifier))
//                 return false;
//             URLResourceIdentifier other = (URLResourceIdentifier) object;
//             if (requestMethod != other.requestMethod)
//                 return false;
//             // rest array is not nessary
//             if (fragments.size() != other.fragments.size())
//                 return false;
//             for (int i = 0; i != fragments.size(); i++) {
//                 if (!(fragments.get(i).charAt(0) == VARIABLE || other.fragments.get(i).charAt(0) == VARIABLE || fragments.get(i).equals(other.fragments.get(i))))
//                     return false;
//             }
// 
//             return true;
//         }
// 
//         /**
//          * TODO : more URL fileds to hash. inefficient hash searching !
//          *
//          * we calculater hash code without url rest terms array content,
//          * it will same as even rest array is diffrent. this can cause hashcode
//          * is equaled when http method and url terms array size are same.
//          *
//          * HashMap (K, V) use hashcode() to determine which bucket is
//          * used to hold the Entry. but get() use hashcode() and equals() to search
//          * the Entry. so the correctness has no affected but search performance
//          * on non-exist Entry searching.
//          */
//         @Override
//         public int hashCode() {
//             return requestMethod.name().hashCode() + fragments.size();
//         }
// 
//         @Override
//         public String toString() {
//             return String.format("%s, %s", requestMethod.name(), Joiner.on("/").skipNulls().join(fragments));
//         }
//     }
// }
// 
// Path: core/src/main/java/org/nesty/core/server/rest/controller/URLController.java
// public class URLController extends Hitcounter {
// 
//     // target class
//     private ControllerClassDescriptor provider;
//     // target method
//     private ControllerMethodDescriptor procedure;
//     // internal controller sign. only for root-path
//     private boolean internal = false;
// 
//     private URLController() {
// 
//     }
// 
//     public static URLController fromProvider(String URI, Class<?> providerClass, Method procedure) {
//         URLController handler = new URLController();
//         handler.provider = new ControllerClassDescriptor(providerClass);
//         handler.procedure = new ControllerMethodDescriptor(URI, handler.provider, procedure);
//         return handler;
//     }
// 
//     public URLController internal() {
//         this.internal = true;
//         return this;
//     }
// 
//     public boolean isInternal() {
//         return this.internal;
//     }
// 
//     public HttpResult call(HttpContext context) {
//         /**
//          * make new controller class instance with every http request. because
//          * of we desire every request may has own context variables and status.
//          *
//          * TODO : This newInstance() need a empty param default constructor.
//          *
//          */
// 
//         try {
//             Object result = procedure.invoke(context);
//             if (result != null && !result.getClass().isPrimitive())
//                 return new HttpResult(ResultCode.SUCCESS, result);
//             else
//                 return new HttpResult(ResultCode.RESPONSE_NOT_VALID);
//         } catch (ControllerParamsNotMatchException e) {
//             return new HttpResult(ResultCode.PARAMS_NOT_MATCHED);
//         } catch (ControllerParamsParsedException e) {
//             return new HttpResult(ResultCode.PARAMS_CONVERT_ERROR);
//         }
//     }
// 
//     @Override
//     public String toString() {
//         return String.format("provider=%s, procedure=%s", provider.getClazz().getCanonicalName(), procedure.getMethod().getName());
//     }
// }


import org.nesty.core.server.rest.URLResource;
import org.nesty.core.server.rest.controller.URLController;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
package org.nesty.core.server;



public class NestyServerMonitor {

    // total missed request times
    static final AtomicLong requestMiss = new AtomicLong();
    // total hit request times
    static final AtomicLong requestHit = new AtomicLong();
    // total connections on current
    static final AtomicLong connections = new AtomicLong();
    // all URLResource mapping for hit count
// Path: core/src/main/java/org/nesty/core/server/rest/URLResource.java
// public class URLResource {
// 
//     // variable flag
//     public static final char VARIABLE = '{';
//     // resource identifier
//     private URLResourceIdentifier identifier;
// 
//     private URLResource() {
// 
//     }
// 
//     public static URLResource fromHttp(String url, RequestMethod requestMethod) {
//         URLResource resource = new URLResource();
//         resource.identifier = URLResourceIdentifier.analyse(url);
//         resource.identifier.requestMethod = requestMethod;
//         return resource;
//     }
// 
//     public RequestMethod requestMethod() {
//         return identifier.requestMethod;
//     }
// 
//     public List<String> fragments() {
//         return identifier.fragments;
//     }
// 
//     @Override
//     public String toString() {
//         return identifier.toString();
//     }
// 
//     @Override
//     public int hashCode() {
//         return identifier.hashCode();
//     }
// 
//     @Override
//     public boolean equals(Object other) {
//         return !(other == null || !(other instanceof URLResource)) && identifier.equals(((URLResource) other).identifier);
//     }
// 
//     /**
//      * URLResource uniqu identifier member. used for URLResource
//      * equals and hashcode id
//      */
//     static class URLResourceIdentifier {
//         protected List<String> fragments = new ArrayList<>(64);
//         protected RequestMethod requestMethod;
// 
//         public static URLResourceIdentifier analyse(String url) {
//             url = HttpUtils.truncateUrl(url);
//             URLResourceIdentifier identifier = new URLResourceIdentifier();
//             for (String s : Splitter.on('/').trimResults().omitEmptyStrings().split(url))
//                 identifier.fragments.add(s);
//             return identifier;
//         }
// 
//         @Override
//         public boolean equals(Object object) {
//             if (object == null || !(object instanceof URLResourceIdentifier))
//                 return false;
//             URLResourceIdentifier other = (URLResourceIdentifier) object;
//             if (requestMethod != other.requestMethod)
//                 return false;
//             // rest array is not nessary
//             if (fragments.size() != other.fragments.size())
//                 return false;
//             for (int i = 0; i != fragments.size(); i++) {
//                 if (!(fragments.get(i).charAt(0) == VARIABLE || other.fragments.get(i).charAt(0) == VARIABLE || fragments.get(i).equals(other.fragments.get(i))))
//                     return false;
//             }
// 
//             return true;
//         }
// 
//         /**
//          * TODO : more URL fileds to hash. inefficient hash searching !
//          *
//          * we calculater hash code without url rest terms array content,
//          * it will same as even rest array is diffrent. this can cause hashcode
//          * is equaled when http method and url terms array size are same.
//          *
//          * HashMap (K, V) use hashcode() to determine which bucket is
//          * used to hold the Entry. but get() use hashcode() and equals() to search
//          * the Entry. so the correctness has no affected but search performance
//          * on non-exist Entry searching.
//          */
//         @Override
//         public int hashCode() {
//             return requestMethod.name().hashCode() + fragments.size();
//         }
// 
//         @Override
//         public String toString() {
//             return String.format("%s, %s", requestMethod.name(), Joiner.on("/").skipNulls().join(fragments));
//         }
//     }
// }
// 
// Path: core/src/main/java/org/nesty/core/server/rest/controller/URLController.java
// public class URLController extends Hitcounter {
// 
//     // target class
//     private ControllerClassDescriptor provider;
//     // target method
//     private ControllerMethodDescriptor procedure;
//     // internal controller sign. only for root-path
//     private boolean internal = false;
// 
//     private URLController() {
// 
//     }
// 
//     public static URLController fromProvider(String URI, Class<?> providerClass, Method procedure) {
//         URLController handler = new URLController();
//         handler.provider = new ControllerClassDescriptor(providerClass);
//         handler.procedure = new ControllerMethodDescriptor(URI, handler.provider, procedure);
//         return handler;
//     }
// 
//     public URLController internal() {
//         this.internal = true;
//         return this;
//     }
// 
//     public boolean isInternal() {
//         return this.internal;
//     }
// 
//     public HttpResult call(HttpContext context) {
//         /**
//          * make new controller class instance with every http request. because
//          * of we desire every request may has own context variables and status.
//          *
//          * TODO : This newInstance() need a empty param default constructor.
//          *
//          */
// 
//         try {
//             Object result = procedure.invoke(context);
//             if (result != null && !result.getClass().isPrimitive())
//                 return new HttpResult(ResultCode.SUCCESS, result);
//             else
//                 return new HttpResult(ResultCode.RESPONSE_NOT_VALID);
//         } catch (ControllerParamsNotMatchException e) {
//             return new HttpResult(ResultCode.PARAMS_NOT_MATCHED);
//         } catch (ControllerParamsParsedException e) {
//             return new HttpResult(ResultCode.PARAMS_CONVERT_ERROR);
//         }
//     }
// 
//     @Override
//     public String toString() {
//         return String.format("provider=%s, procedure=%s", provider.getClazz().getCanonicalName(), procedure.getMethod().getName());
//     }
// }


// Path: core/src/main/java/org/nesty/core/server/NestyServerMonitor.java
import org.nesty.core.server.rest.URLResource;
import org.nesty.core.server.rest.controller.URLController;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;

package org.nesty.core.server;



public class NestyServerMonitor {

    // total missed request times
    static final AtomicLong requestMiss = new AtomicLong();
    // total hit request times
    static final AtomicLong requestHit = new AtomicLong();
    // total connections on current
    static final AtomicLong connections = new AtomicLong();
    // all URLResource mapping for hit count
    static Map<URLResource, URLController> resourceMap = new HashMap<>();