/** {@inheritDoc} */
  public synchronized void destroy() {

    String s = config.getInitParameter(ApplicationConfig.SHARED);
    if (s != null && s.equalsIgnoreCase("true")) {
      logger.warn(
          "Factory shared, will not be destroyed. That can possibly cause memory leaks if"
              + "Broadcaster where created. Make sure you destroy them manually.");
      return;
    }

    Enumeration<Broadcaster> e = store.elements();
    Broadcaster b;
    // We just need one when shared.
    BroadcasterConfig bc = null;
    while (e.hasMoreElements()) {
      try {
        b = e.nextElement();
        b.resumeAll();
        b.destroy();
        bc = b.getBroadcasterConfig();
      } catch (Throwable t) {
        // Shield us from any bad behaviour
        logger.trace("Destroy", t);
      }
    }

    try {
      if (bc != null) bc.forceDestroy();
    } catch (Throwable t) {
      logger.trace("Destroy", t);
    }

    store.clear();
    factory = null;
  }
示例#2
0
 /** Close all the cached connections. */
 public void closeAll() {
   for (Enumeration<Socket> values = socketTable.elements(); values.hasMoreElements(); ) {
     Socket s = (Socket) values.nextElement();
     try {
       s.close();
     } catch (IOException ex) {
     }
   }
 }
  /**
   * ********************************************************************************************
   */
  @GET
  @Path("/testSim")
  public Response testSim() {

    // try to get the last two SFPs from the sfplist
    java.util.Enumeration<String> enu = sfplist.elements();
    ArrayList<String> entries = Collections.list(enu);
    System.out.println("No of entries in FP list: " + entries.size());
    if (entries.size() < 2)
      return Response.status(Status.NOT_FOUND)
          .entity("Less than two fingerprints in sfplist ... nothing to compare")
          .build();
    String sfp1 = "";
    String sfp2 = "";
    try {
      sfp1 = entries.get(0);
      sfp2 = entries.get(1);
    } catch (Exception e) {
      e.printStackTrace();
    }
    Client client = Client.create();

    WebResource webResource =
        client.resource("http://localhost:10080/Guinan/webapp/similarity/getSim");

    HashMap<String, String> params = new HashMap<String, String>();
    params.put("sfp1", sfp1);
    params.put("sfp2", sfp2);

    // String input = "{\"sfp1\":\""+sfp1+"\",\"sfp2\":\""+sfp2+"\"}";
    // System.out.println("Input for similarity: "+input);
    ObjectMapper mapper = new ObjectMapper();
    String input = "";
    try {
      input = mapper.writeValueAsString(params);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return Response.status(Status.INTERNAL_SERVER_ERROR).build();
    }
    System.out.println("JSON input: ");
    ClientResponse response =
        webResource.type(MediaType.APPLICATION_JSON).post(ClientResponse.class, input);

    System.out.println("Response from Service: " + response.getStatus() + "\n\n ");

    System.out.println("Output from Server .... \n");
    String output = response.getEntity(String.class);

    return Response.status(Status.OK).entity(output).build();
  }
  public static void main(String[] args) {
    ConcurrentHashMap<String, Integer> vehicles = new ConcurrentHashMap();

    /* Add some vehicles. */
    vehicles.put("BMW", 5);
    vehicles.put("Mercedes", 3);
    vehicles.put("Audi", 4);
    vehicles.put("Ford", 10);

    System.out.println("Total vehicles: " + vehicles.size());

    /* Iterate over all vehicles, using the keySet method. */
    for (String key : vehicles.keySet()) System.out.println(key + " - " + vehicles.get(key));

    System.out.println("-----------------------------------");

    String searchKey = "Audi";
    if (vehicles.containsKey(searchKey))
      System.out.println("Found total '" + vehicles.get(searchKey) + "' " + searchKey + " cars!\n");

    Enumeration elems = vehicles.elements();
    while (elems.hasMoreElements()) System.out.println(elems.nextElement());

    System.out.println("-----------------------------------");

    Integer val = vehicles.putIfAbsent("Audi", 9);
    if (val != null) System.out.println("Audi was found in the map and its value was updated!");

    val = vehicles.putIfAbsent("Nissan", 9);
    if (val == null) System.out.println("Nissan wasn't found in map, thus a new pair was created!");

    System.out.println("-----------------------------------");

    // The next statements throw a NullPointerException, if uncommented.
    // vehicles.put("Nissan", null);
    // vehicles.put(null, 6);

    /* Clear all values. */
    vehicles.clear();

    /* Equals to zero. */
    System.out.println("After clear operation, size: " + vehicles.size());
  }
示例#5
0
  /** 提交事务 */
  public void commit() {
    if (txInterrupted) {
      writeErrMessage(ErrorCode.ER_YES, "Transaction error, need to rollback.");
    } else {
      final int initCount = target.size();
      if (initCount <= 0) {
        this.writeOK();
        return;
      } else if (initCount == 1) {
        BackendConnection con = target.elements().nextElement();
        commitHandler.commit(con);

      } else {

        if (LOGGER.isDebugEnabled()) {
          LOGGER.debug("multi node commit to send ,total " + initCount);
        }
        multiNodeCoordinator.executeBatchNodeCmd(SQLCmdConstant.COMMIT_CMD);
      }
    }
  }
 /**
  * Get all the SAMLSSOServiceProviderDO objects which are registered through the OSGi service.
  *
  * @return Enumeration of SAMLSSOServiceProviderDO objects
  */
 public Enumeration<SAMLSSOServiceProviderDO> getAllServiceProviders() {
   return serviceProviderMap.elements();
 }