com.hazelcast.core.HazelcastException Java Examples

The following examples show how to use com.hazelcast.core.HazelcastException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RetryUtils.java    From hazelcast-kubernetes with Apache License 2.0 5 votes vote down vote up
private static void sleep(long millis) {
    try {
        Thread.sleep(millis);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new HazelcastException(e);
    }
}
 
Example #2
Source File: DnsEndpointResolver.java    From hazelcast-kubernetes with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("checkstyle:magicnumber")
private static DirContext createDirContext(int serviceDnsTimeout) {
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory");
    env.put(Context.PROVIDER_URL, "dns:");
    env.put("com.sun.jndi.dns.timeout.initial", String.valueOf(serviceDnsTimeout * 1000L));
    try {
        return new InitialDirContext(env);
    } catch (NamingException e) {
        throw new HazelcastException("Error while initializing DirContext", e);
    }
}
 
Example #3
Source File: RetryUtilsTest.java    From hazelcast-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test(expected = HazelcastException.class)
public void retryRetriesFailedUncheckedException()
        throws Exception {
    // given
    given(callable.call()).willThrow(new Exception()).willThrow(new Exception()).willReturn(RESULT);

    // when
    RetryUtils.retry(callable, RETRIES, Collections.<String>emptyList());

    // then
    // throws exception
}
 
Example #4
Source File: TranslationFacade.java    From modernmt with Apache License 2.0 4 votes vote down vote up
public Translation get(UUID user, LanguageDirection direction, Preprocessor.Options preprocessingOptions, String text, ContextVector translationContext, int nbest, Priority priority, long timeout) throws ProcessingException, DecoderException {
    direction = mapLanguage(direction);
    if (nbest > 0)
        ensureDecoderSupportsNBest();

    Engine engine = ModernMT.getNode().getEngine();
    Preprocessor preprocessor = engine.getPreprocessor();
    Postprocessor postprocessor = engine.getPostprocessor();

    // Pre-processing text
    Sentence sentence = preprocessor.process(direction, text, preprocessingOptions);

    // Translating
    Translation translation;
    long expirationTimestamp = timeout > 0 ? (System.currentTimeMillis() + timeout) : 0L;

    try {
        translation = insecureGet(user, direction, sentence, translationContext, nbest, priority, expirationTimestamp);
    } catch (DecoderException | HazelcastException e) {
        if (e instanceof TranslationTimeoutException)
            throw e;

        logger.warn("Translation failed, retry after delay", e);

        try {
            Thread.sleep(50);
        } catch (InterruptedException e1) {
            // Ignore it
        }

        translation = insecureGet(user, direction, sentence, translationContext, nbest, priority, expirationTimestamp);
    }

    // Post-processing translation
    postprocessor.process(direction, translation);

    if (translation.hasNbest()) {
        List<Translation> hypotheses = translation.getNbest();
        postprocessor.process(direction, hypotheses);
    }

    return translation;
}