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());
      }
    }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
 /** 关闭连接 */
 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);
 }
Ejemplo n.º 4
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);
    }
  }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
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);
    }
  }
Ejemplo n.º 7
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);
 }