void await() {
   try {
     latch.await();
   } catch (InterruptedException e) {
     EmptyStatement.ignore(e);
   }
 }
示例#2
0
 private void sleepForProxyInitRetry() {
   try {
     Thread.sleep(TimeUnit.SECONDS.toMillis(ClientInvocation.RETRY_WAIT_TIME_IN_SECONDS));
   } catch (InterruptedException ignored) {
     EmptyStatement.ignore(ignored);
   }
 }
示例#3
0
  @SuppressWarnings({"checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity"})
  protected Collection<Address> getPossibleAddresses() {
    final Collection<String> possibleMembers = getMembers();
    final Set<Address> possibleAddresses = new HashSet<Address>();
    final NetworkConfig networkConfig = config.getNetworkConfig();
    for (String possibleMember : possibleMembers) {
      AddressHolder addressHolder = AddressUtil.getAddressHolder(possibleMember);
      try {
        boolean portIsDefined =
            addressHolder.getPort() != -1 || !networkConfig.isPortAutoIncrement();
        int count = portIsDefined ? 1 : maxPortTryCount;
        int port =
            addressHolder.getPort() != -1 ? addressHolder.getPort() : networkConfig.getPort();
        AddressMatcher addressMatcher = null;
        try {
          addressMatcher = AddressUtil.getAddressMatcher(addressHolder.getAddress());
        } catch (InvalidAddressException ignore) {
          EmptyStatement.ignore(ignore);
        }
        if (addressMatcher != null) {
          final Collection<String> matchedAddresses;
          if (addressMatcher.isIPv4()) {
            matchedAddresses = AddressUtil.getMatchingIpv4Addresses(addressMatcher);
          } else {
            // for IPv6 we are not doing wildcard matching
            matchedAddresses = Collections.singleton(addressHolder.getAddress());
          }
          for (String matchedAddress : matchedAddresses) {
            addPossibleAddresses(
                possibleAddresses, null, InetAddress.getByName(matchedAddress), port, count);
          }
        } else {
          final String host = addressHolder.getAddress();
          final InterfacesConfig interfaces = networkConfig.getInterfaces();
          if (interfaces.isEnabled()) {
            final InetAddress[] inetAddresses = InetAddress.getAllByName(host);
            for (InetAddress inetAddress : inetAddresses) {
              if (AddressUtil.matchAnyInterface(
                  inetAddress.getHostAddress(), interfaces.getInterfaces())) {
                addPossibleAddresses(possibleAddresses, host, inetAddress, port, count);
              }
            }
          } else {
            addPossibleAddresses(possibleAddresses, host, null, port, count);
          }
        }
      } catch (UnknownHostException e) {
        logger.warning(
            "Cannot resolve hostname '"
                + addressHolder.getAddress()
                + "'. Please make sure host is valid and reachable.");
        if (logger.isFinestEnabled()) {
          logger.finest("Error during resolving possible target!", e);
        }
      }
    }

    possibleAddresses.remove(node.getThisAddress());
    return possibleAddresses;
  }
示例#4
0
  private void ensureConnectionToAllMembers() {
    boolean allConnected = false;
    if (node.joined()) {
      logger.finest("Waiting for all connections");
      int connectAllWaitSeconds =
          node.groupProperties.getSeconds(GroupProperty.CONNECT_ALL_WAIT_SECONDS);
      int checkCount = 0;
      while (checkCount++ < connectAllWaitSeconds && !allConnected) {
        try {
          //noinspection BusyWait
          TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException ignored) {
          EmptyStatement.ignore(ignored);
        }

        allConnected = true;
        Collection<Member> members = clusterService.getMembers();
        for (Member member : members) {
          if (!member.localMember()
              && node.connectionManager.getOrConnect(member.getAddress()) == null) {
            allConnected = false;
            if (logger.isFinestEnabled()) {
              logger.finest("Not-connected to " + member.getAddress());
            }
          }
        }
      }
    }
  }
 void join() {
   try {
     completedLatch.await();
   } catch (InterruptedException e) {
     EmptyStatement.ignore(e);
   }
 }
 private void sleep() {
   try {
     Thread.sleep(TimeUnit.SECONDS.toMillis(RETRY_WAIT_TIME_IN_SECONDS));
   } catch (InterruptedException ignored) {
     EmptyStatement.ignore(ignored);
   }
 }
 public static void closeQuietly(Closeable closeable) {
   if (closeable == null) {
     return;
   }
   try {
     closeable.close();
   } catch (IOException ignored) {
     EmptyStatement.ignore(ignored);
   }
 }
 void stop() {
   if (started.compareAndSet(true, false)) {
     try {
       thread.isRunning = false;
       thread.interrupt();
       thread.join(TimeUnit.SECONDS.toMillis(5));
     } catch (InterruptedException e) {
       EmptyStatement.ignore(e);
     }
   }
 }
示例#9
0
 public static void shutdownAll() {
   for (HazelcastClientProxy proxy : CLIENTS.values()) {
     try {
       proxy.client.getLifecycleService().shutdown();
     } catch (Exception ignored) {
       EmptyStatement.ignore(ignored);
     }
     proxy.client = null;
   }
   CLIENTS.clear();
 }
  public static void main(String[] args) {
    // enter your licenceKey below
    String licenceKey = "---- LICENCE KEY ----";
    Config config = createConfig(licenceKey);
    Hazelcast.newHazelcastInstance(config);

    HazelcastInstance client = HazelcastClient.newHazelcastClient();
    IMap<Object, Object> acceptedMap = client.getMap(ACCEPTED_MAP_NAME);
    IMap<Object, Object> deniedMap = client.getMap(DENIED_MAP_NAME);

    acceptedMap.put(ACCEPTED_KEY, ACCEPTED_VALUE);

    try {
      deniedMap.put(ACCEPTED_KEY, ACCEPTED_VALUE);
      System.err.println("Should be denied!!!!");
    } catch (Exception expected) {
      EmptyStatement.ignore(expected);
    }

    try {
      acceptedMap.put(ACCEPTED_KEY, DENIED_VALUE);
      System.err.println("Should be denied!!!!");
    } catch (Exception expected) {
      EmptyStatement.ignore(expected);
    }

    try {
      acceptedMap.put(DENIED_KEY, ACCEPTED_VALUE);
      System.err.println("Should be denied!!!!");
    } catch (Exception expected) {
      EmptyStatement.ignore(expected);
    }

    try {
      acceptedMap.replace(ACCEPTED_KEY, ACCEPTED_VALUE);
      System.err.println("Should be denied!!!!");
    } catch (Exception expected) {
      EmptyStatement.ignore(expected);
    }
  }
 @Override
 protected void readInternal(ObjectDataInput in) throws IOException {
   super.readInternal(in);
   stateName = in.readUTF();
   try {
     newState = ClusterState.valueOf(stateName);
   } catch (IllegalArgumentException ignored) {
     EmptyStatement.ignore(ignored);
   }
   initiator = new Address();
   initiator.readData(in);
   txnId = in.readUTF();
 }
示例#12
0
 @SuppressWarnings("unchecked")
 private Object createServiceObject(String className) {
   try {
     ClassLoader classLoader = nodeEngine.getConfigClassLoader();
     Class serviceClass = ClassLoaderUtil.loadClass(classLoader, className);
     try {
       Constructor constructor = serviceClass.getConstructor(NodeEngine.class);
       return constructor.newInstance(nodeEngine);
     } catch (NoSuchMethodException ignored) {
       ignore(ignored);
     }
     return ClassLoaderUtil.newInstance(serviceClass, classLoader, className);
   } catch (Exception e) {
     logger.severe(e);
   }
   return null;
 }
  public void shutdown() {
    logger.finest("Shutting down OperationService");

    invocationRegistry.shutdown();
    invocationMonitor.shutdown();
    operationExecutor.shutdown();
    asyncResponseHandler.shutdown();
    slowOperationDetector.shutdown();

    try {
      invocationMonitor.awaitTermination(TERMINATION_TIMEOUT_MILLIS);
    } catch (InterruptedException e) {
      // restore the interrupt.
      // todo: we need a better mechanism for dealing with interruption and waiting for termination
      Thread.currentThread().interrupt();
      EmptyStatement.ignore(e);
    }
  }
  @Test
  public void whenError_andNoSpace() {
    for (int k = 0; k < ringbuffer.capacity(); k++) {
      topic.publish("old");
    }

    long tail = ringbuffer.tailSequence();
    long head = ringbuffer.headSequence();

    try {
      topic.publish("new");
      fail();
    } catch (TopicOverloadException expected) {
      EmptyStatement.ignore(expected);
    }

    assertEquals(tail, ringbuffer.tailSequence());
    assertEquals(head, ringbuffer.headSequence());
  }
示例#15
0
  protected JoinMessage sendSplitBrainJoinMessage(Address target) {
    if (logger.isFinestEnabled()) {
      logger.finest(node.getThisAddress() + " is connecting to " + target);
    }

    Connection conn = node.connectionManager.getOrConnect(target, true);
    long timeout = SPLIT_BRAIN_CONN_TIMEOUT;
    while (conn == null) {
      timeout -= SPLIT_BRAIN_SLEEP_TIME;
      if (timeout < 0) {
        return null;
      }
      try {
        //noinspection BusyWait
        Thread.sleep(SPLIT_BRAIN_SLEEP_TIME);
      } catch (InterruptedException e) {
        EmptyStatement.ignore(e);
        return null;
      }
      conn = node.connectionManager.getConnection(target);
    }

    NodeEngine nodeEngine = node.nodeEngine;
    Future future =
        nodeEngine
            .getOperationService()
            .createInvocationBuilder(
                ClusterServiceImpl.SERVICE_NAME,
                new JoinCheckOperation(node.createSplitBrainJoinMessage()),
                target)
            .setTryCount(1)
            .invoke();
    try {
      return (JoinMessage) future.get(SPLIT_BRAIN_JOIN_CHECK_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    } catch (TimeoutException e) {
      logger.finest("Timeout during join check!", e);
    } catch (Exception e) {
      logger.warning("Error during join check!", e);
    }
    return null;
  }