示例#1
0
 /**
  * This method will open a filtered Http Connection.
  *
  * @see net.rim.device.api.io.FilterBaseInterface#openFilter(String, int, boolean)
  */
 public Connection openFilter(String name, int mode, boolean timeouts) throws IOException {
   try {
     final Request request = new Request(name);
     log.debug("Intercept krypsis request: " + name);
     final Response response = dispatchRequest(request);
     return response == null ? null : new KrypsisConnection(response, Main.HOST);
   } catch (RequestException e) {
     log.debug("Not a crypsis request. Pass it to the network");
     return Connector.open("http:" + name + ";usefilter=false", mode, timeouts);
   }
 }
示例#2
0
 public ResponseQueue getResponseQueue() {
   ResponseQueue queue = (ResponseQueue) getGlobalScope().get(QUEUE);
   if (queue == null) {
     log.debug("Create response queue with a size of 32");
     queue = new ResponseQueue(32);
     getGlobalScope().put(QUEUE, queue);
   }
   return queue;
 }
示例#3
0
  /**
   * Dispatches the given request. If the responsible module is not available then an error response
   * will be returned.
   *
   * @param request The request to dispatch.
   * @return A response to the given request or null.
   */
  public Response dispatchRequest(Request request) {

    /*
     If this is a queue request, then return the next request
     from the queue.
    */
    if (ModuleContext.QUEUE.equals(request.getModuleContext())) {
      final long begin = System.currentTimeMillis();
      log.debug("Queue: Wait for response...");
      final Response response = getResponseQueue().get(QUEUE_TIMEOUT);
      final long end = System.currentTimeMillis();
      log.debug(
          "Queue: Returned after "
              + (end - begin)
              + " ms "
              + (response == null ? "without" : "with")
              + " a response: =>"
              + response);
      /* The queue response must not be null but an empty response */
      return response == null ? new EmptyResponse(request) : response;
    }

    final Module module = getRegistry().getModule(request.getModuleContext());
    if (module == null) {
      log.error(
          "Requested module '" + request.getModuleContext() + "' is not implemented or registered");
      dispatch(new ErrorResponse(request, ErrorResponse.MODULE_NOT_SUPPORTED));
    } else {
      log.debug(
          "Module '"
              + request.getModuleContext()
              + "' created. Execute action '"
              + request.getAction()
              + "' ...");
      module.handle(request, this);
    }

    return null;
  }