public void invoke(MethodInvocation invocation) throws Throwable {
      if (current.get() != null) {
        // Already invoking a method on the mix-in
        return;
      }

      if (instance == null) {
        instance = DirectInstantiator.INSTANCE.newInstance(mixInClass, proxy);
      }
      MethodInvocation beanInvocation =
          new MethodInvocation(
              invocation.getName(),
              invocation.getReturnType(),
              invocation.getGenericReturnType(),
              invocation.getParameterTypes(),
              instance,
              invocation.getParameters());
      current.set(beanInvocation);
      try {
        next.invoke(beanInvocation);
      } finally {
        current.set(null);
      }
      if (beanInvocation.found()) {
        invocation.setResult(beanInvocation.getResult());
      }
    }
예제 #2
0
파일: DBManager.java 프로젝트: kone/kin
 /** 关闭连接 */
 public static final void closeConnection() {
   Connection conn = conns.get();
   try {
     if (conn != null && !conn.isClosed()) {
       conn.setAutoCommit(true);
       conn.close();
       connectionContext.remove(Thread.currentThread().getId());
     }
   } catch (SQLException e) {
     log.error("Unabled to close connection!!! ", e);
   }
   conns.set(null);
 }
예제 #3
0
 // When finished, invoker must ensure that selector is empty
 // by cancelling any related keys and explicitly releasing
 // the selector by invoking releaseTemporarySelector()
 static Selector getTemporarySelector(SelectableChannel sc) throws IOException {
   SoftReference ref = (SoftReference) localSelector.get();
   SelectorWrapper selWrapper = null;
   Selector sel = null;
   if (ref == null
       || ((selWrapper = (SelectorWrapper) ref.get()) == null)
       || ((sel = selWrapper.get()) == null)
       || (sel.provider() != sc.provider())) {
     sel = sc.provider().openSelector();
     localSelector.set(new SoftReference(new SelectorWrapper(sel)));
   } else {
     localSelectorWrapper.set(selWrapper);
   }
   return sel;
 }
예제 #4
0
  /** Returns a temporary buffer of at least the given size */
  public static ByteBuffer getTemporaryDirectBuffer(int size) {
    // If a buffer of this size is too large for the cache, there
    // should not be a buffer in the cache that is at least as
    // large. So we'll just create a new one. Also, we don't have
    // to remove the buffer from the cache (as this method does
    // below) given that we won't put the new buffer in the cache.
    if (isBufferTooLarge(size)) {
      return ByteBuffer.allocateDirect(size);
    }

    BufferCache cache = bufferCache.get();
    ByteBuffer buf = cache.get(size);
    if (buf != null) {
      return buf;
    } else {
      // No suitable buffer in the cache so we need to allocate a new
      // one. To avoid the cache growing then we remove the first
      // buffer from the cache and free it.
      if (!cache.isEmpty()) {
        buf = cache.removeFirst();
        free(buf);
      }
      return ByteBuffer.allocateDirect(size);
    }
  }
예제 #5
0
파일: DBManager.java 프로젝트: kone/kin
 public static final Connection getConnection() throws SQLException {
   Connection conn = conns.get();
   if (conn == null || conn.isClosed()) {
     conn = _getConnection();
     if (conn == null) throw new SQLException("Unabled to get connection.");
     conns.set(conn);
     // RequestContext ctx = RequestContext.get();
     // connectionContext.put(
     // Thread.currentThread().getId(),
     // new ConnectionContext(new Exception(), (ctx != null) ? ctx
     // .ip() : null, (ctx != null) ? ctx.uri() : null,
     // (ctx != null) ? ctx.request().getParameterMap()
     // : null));
   }
   return (show_sql && !Proxy.isProxyClass(conn.getClass()))
       ? new _DebugConnection(conn).getConnection()
       : conn;
 }
예제 #6
0
  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {

    httpRequestContext.set(new HttpRequestContext(this, req, resp));

    String pinfo = req.getPathInfo();
    if (pinfo == null) return;
    try {
      callMethodForParam(req, resp);
    } catch (Exception e) {
      e.printStackTrace();
      throw new ServletException(e);
    }
  }
예제 #7
0
  /**
   * Releases a temporary buffer by returning to the cache or freeing it. If returning to the cache
   * then insert it at the end. This makes it suitable for scatter/gather operations where the
   * buffers are returned to cache in same order that they were obtained.
   */
  static void offerLastTemporaryDirectBuffer(ByteBuffer buf) {
    // If the buffer is too large for the cache we don't have to
    // check the cache. We'll just free it.
    if (isBufferTooLarge(buf)) {
      free(buf);
      return;
    }

    assert buf != null;
    BufferCache cache = bufferCache.get();
    if (!cache.offerLast(buf)) {
      // cache is full
      free(buf);
    }
  }
예제 #8
0
  public void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    httpRequestContext.set(new HttpRequestContext(this, req, resp));

    try {
      String ctype = req.getContentType();
      if (ctype != null) ctype = ctype.toLowerCase();
      if (FileUpload.isMultipartContent(req)) {
        callMethodForMultiPart(req, resp);
      } else if (MIME_JSON.equals(ctype)) {
        // TODO: json-rpc
      } else {
        callMethodForParam(req, resp);
      }
    } catch (Exception e) {
      e.printStackTrace();
      throw new ServletException(e);
    }
  }
예제 #9
0
 static Object createArgumentPlaceholder(Class<?> clazz) {
   return isLimitedValues(clazz)
       ? LIMITED_VALUE_ARGUMENTS.get().getNextPlaceholder(clazz)
       : createArgumentPlaceholder(clazz, PLACEHOLDER_COUNTER.addAndGet(1));
 }
예제 #10
0
 public static HttpRequestContext getHttpRequestContext() {
   return httpRequestContext.get();
 }
예제 #11
0
 static void releaseTemporarySelector(Selector sel) throws IOException {
   // Selector should be empty
   sel.selectNow(); // Flush cancelled keys
   assert sel.keys().isEmpty() : "Temporary selector not empty";
   localSelectorWrapper.set(null);
 }