Exemplo n.º 1
0
  public static void main(String[] args) {

    // Service service = new Service();
    // service.runSomething();

    IService service = new Proxy();
    service.runSomething();
  }
Exemplo n.º 2
0
  @Test
  public void testASync() throws InterruptedException, ExecutionException {
    Future<String> asyncText = service.getAsyncText();
    System.out.println("Passed");

    // get & wait response
    System.out.println(asyncText.get());
  }
  /**
   * Blocking operation to resolve into the adaptee, if available.
   *
   * <p>Required adaptions:
   *
   * <ul>
   *   <li>GeoResource.class - this
   *   <li>IGeoResourceInfo.class - getInfo( monitor ) ie about this handles contents
   *   <li>IService.class - service( monitor ) ie that is responsible for this GeoResource
   * </ul>
   *
   * <p>Example Use (no casting required!):
   *
   * <pre>
   * <code>
   * IGeoResourceInfo info = resolve(IGeoResourceInfo.class);
   * </code>
   * </pre>
   *
   * <p>Recommended adaptions:
   *
   * <ul>
   *   <li>ImageDescriptor.class (for icon provided by external service)
   *   <li>List.class - members( monitor ) ie children of this georesource as in the wms layer case
   * </ul>
   *
   * @param adaptee
   * @param monitor
   * @return instance of adaptee, or null if unavailable (IGeoResourceInfo and IService must be
   *     supported)
   * @see IGeoResourceInfo
   * @see IService
   * @see IResolve#resolve(Class, IProgressMonitor)
   */
  public <T> T resolve(Class<T> adaptee, IProgressMonitor monitor) throws IOException {

    if (monitor == null) monitor = new NullProgressMonitor();

    if (adaptee == null) {
      throw new NullPointerException("No adaptor specified"); // $NON-NLS-1$
    }
    if (adaptee.isAssignableFrom(IGeoResourceInfo.class)) {
      return adaptee.cast(getInfo(monitor));
    }
    if (adaptee.isAssignableFrom(IService.class)) {
      return adaptee.cast(service(monitor));
    }
    if (adaptee.isAssignableFrom(IServiceInfo.class)) {
      try {
        monitor.beginTask("service info", 100); // $NON-NLS-1$
        IService service = service(new SubProgressMonitor(monitor, 40));
        if (service != null) {
          IServiceInfo info = service.getInfo(new SubProgressMonitor(monitor, 60));
          return adaptee.cast(info);
        }
      } finally {
        monitor.done();
      }
    }
    if (adaptee.isAssignableFrom(IGeoResource.class)) {
      monitor.done();
      return adaptee.cast(this);
    }
    if (adaptee.isAssignableFrom(getClass())) {
      return adaptee.cast(this);
    }
    IResolveManager rm = CatalogPlugin.getDefault().getResolveManager();
    if (rm.canResolve(this, adaptee)) {
      return rm.resolve(this, adaptee, monitor);
    }
    return null; // no adapter found (check to see if ResolveAdapter is registered?)
  }
Exemplo n.º 4
0
  /**
   * @param pjp
   * @return
   * @throws Throwable
   */
  private static Object processAroundInternal(
      Map svcDef, final ProceedingJoinPoint pjp, LoggerPoint point) throws Throwable {

    long _time = System.currentTimeMillis();
    IService service = (IService) pjp.getTarget();
    String _ip = service.getRemoteHost();
    Integer _logId =
        1; // logBiz.add(Log4Monitor.getClientIpAddress(resource.getHttpServletRequest()), cls, mtd,
    // svcId, (String)svcDef.get("detail"));
    Object retVal = null;
    Integer _code = 200; // 成功
    boolean _error = true;
    try {
      if (point != null) {
        String keys = point.key();
        if ("none".equalsIgnoreCase(keys)) {
          return pjp.proceed();
        }
      }
      retVal = pjp.proceed();
      _error = false;
      if (retVal == null || !Response.class.isAssignableFrom(retVal.getClass())) {
        return retVal;
      }
    } catch (Exception e) {

    } finally {

    }

    IResult _response = (IResult) retVal;

    String _resourceid = getService(pjp, service, point, (Map) svcDef.get(AliasUtil.KEYMAP_KEY));

    StringBuffer tmp = new StringBuffer((String) svcDef.get("className"));
    String _svc =
        tmp.append(".")
            .append((String) svcDef.get("methodName"))
            .append((String) svcDef.get("detail"))
            .toString();
    _resourceid = _resourceid == null ? "" : "resourceid=" + _resourceid;

    final String ip = _ip;
    final String svc = _svc;
    final Integer logId = _logId;
    final String resourceid = _resourceid;
    final boolean error = _error;
    final Integer code = _code;
    _time = System.currentTimeMillis() - _time;
    final long time = _time;
    // 20101223 10:42:22.683 INFO  access - PropResource.useful(uid=1,orderId=2,type="3",targetId=4)
    // code=404 resourceid=1  timeused=69ms
    final String id = null;
    new AsynBizExecutor("logger.info") {
      public void execute() {
        String logInfo = null;

        String svc_ = svc;
        if (id != null) {
          svc_ = id + " " + svc_;
        }
        _logger.info(
            "%s %s code=%d %s %s timeused=%,dms", ip, svc_, code, resourceid, logInfo, time);
      };
    };
    return _response;
  }
Exemplo n.º 5
0
 @Test
 public void testSync() {
   String syncText = service.getSyncText();
   System.out.println(syncText);
 }
 /**
  * Returns a copy of the map of this resource's persistent properties. Returns an empty map if
  * this resource has no persistent properties.
  *
  * @return The map containing the persistent properties where the key is the {@link QualifiedName}
  *     of the property and the value is the {@link String} value of the property.
  */
 public Map<String, Serializable> getPersistentProperties() {
   ID id = this.getID();
   Map<String, Serializable> properties = service.getPersistentProperties(id);
   return properties;
 }
Exemplo n.º 7
0
 public void useService() {
   System.out.println(service.format(new Date()));
 }