Search in sources :

Example 41 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class SetCommandProcessor method handle.

/**
     * "set" means "store this data".
     * <p/>
     * "add" means "store this data, but only if the server *doesn't* already
     * hold data for this key".
     * <p/>
     * "replace" means "store this data, but only if the server *does*
     * already hold data for this key".
     * <p/>
     * <p/>
     * After sending the command line and the data block the client awaits
     * the reply, which may be:
     * <p/>
     * - "STORED\r\n", to indicate success.
     * <p/>
     * - "NOT_STORED\r\n" to indicate the data was not stored, but not
     * because of an error. This normally means that either that the
     * condition for an "add" or a "replace" command wasn't met, or that the
     * item is in a delete queue (see the "delete" command below).
     */
public void handle(SetCommand setCommand) {
    String key = null;
    try {
        key = URLDecoder.decode(setCommand.getKey(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new HazelcastException(e);
    }
    String mapName = DEFAULT_MAP_NAME;
    int index = key.indexOf(':');
    if (index != -1) {
        mapName = MAP_NAME_PRECEDER + key.substring(0, index);
        key = key.substring(index + 1);
    }
    Object value = new MemcacheEntry(setCommand.getKey(), setCommand.getValue(), setCommand.getFlag());
    int ttl = textCommandService.getAdjustedTTLSeconds(setCommand.getExpiration());
    textCommandService.incrementSetCount();
    if (SET == setCommand.getType()) {
        textCommandService.put(mapName, key, value, ttl);
        setCommand.setResponse(TextCommandConstants.STORED);
    } else if (ADD == setCommand.getType()) {
        addCommandType(setCommand, mapName, key, value, ttl);
    } else if (REPLACE == setCommand.getType()) {
        replaceCommandType(setCommand, mapName, key, value, ttl);
    } else if (APPEND == setCommand.getType()) {
        appendCommandType(setCommand, mapName, key, ttl);
    } else if (PREPEND == setCommand.getType()) {
        prependCommandType(setCommand, mapName, key, ttl);
    }
    if (setCommand.shouldReply()) {
        textCommandService.sendResponse(setCommand);
    }
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 42 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class TouchCommandProcessor method handle.

@Override
public void handle(TouchCommand touchCommand) {
    String key;
    try {
        key = URLDecoder.decode(touchCommand.getKey(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new HazelcastException(e);
    }
    String mapName = DEFAULT_MAP_NAME;
    int index = key.indexOf(':');
    if (index != -1) {
        mapName = MAP_NAME_PRECEDER + key.substring(0, index);
        key = key.substring(index + 1);
    }
    int ttl = textCommandService.getAdjustedTTLSeconds(touchCommand.getExpiration());
    try {
        textCommandService.lock(mapName, key);
    } catch (Exception e) {
        touchCommand.setResponse(NOT_STORED);
        if (touchCommand.shouldReply()) {
            textCommandService.sendResponse(touchCommand);
        }
        return;
    }
    final Object value = textCommandService.get(mapName, key);
    textCommandService.incrementTouchCount();
    if (value != null) {
        textCommandService.put(mapName, key, value, ttl);
        touchCommand.setResponse(TOUCHED);
    } else {
        touchCommand.setResponse(NOT_STORED);
    }
    textCommandService.unlock(mapName, key);
    if (touchCommand.shouldReply()) {
        textCommandService.sendResponse(touchCommand);
    }
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HazelcastException(com.hazelcast.core.HazelcastException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 43 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class PostJoinCacheOperationTest method test_cachePostJoinOperationFails_whenJCacheNotAvailable_withCacheConfigs.

@Test
public void test_cachePostJoinOperationFails_whenJCacheNotAvailable_withCacheConfigs() throws Exception {
    // JCache is not available in classpath
    when(JCacheDetector.isJCacheAvailable(classLoader)).thenReturn(false);
    // node engine throws HazelcastException due to missing CacheService
    when(nodeEngine.getService(CacheService.SERVICE_NAME)).thenThrow(new HazelcastException("CacheService not found"));
    // some CacheConfigs are added in the PostJoinCacheOperation (so JCache is actually in use in the rest of the cluster)
    PostJoinCacheOperation postJoinCacheOperation = new PostJoinCacheOperation();
    postJoinCacheOperation.addCacheConfig(new CacheConfig("test"));
    postJoinCacheOperation.setNodeEngine(nodeEngine);
    expectedException.expect(HazelcastException.class);
    postJoinCacheOperation.run();
    verify(nodeEngine).getConfigClassLoader();
    verify(nodeEngine).getService(CacheService.SERVICE_NAME);
    verify(logger, never()).warning(anyString());
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) CacheConfig(com.hazelcast.config.CacheConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 44 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class XmlClientConfigLocator method loadClientHazelcastXmlFromClasspath.

private boolean loadClientHazelcastXmlFromClasspath() {
    URL url = Config.class.getClassLoader().getResource("hazelcast-client.xml");
    if (url == null) {
        LOGGER.finest("Could not find 'hazelcast-client.xml' in classpath.");
        return false;
    }
    LOGGER.info("Loading 'hazelcast-client.xml' from classpath.");
    in = Config.class.getClassLoader().getResourceAsStream("hazelcast-client.xml");
    if (in == null) {
        throw new HazelcastException("Could not load 'hazelcast-client.xml' from classpath");
    }
    return true;
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) Config(com.hazelcast.config.Config) URL(java.net.URL)

Example 45 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class RingbufferContainer method addAll.

/**
     * Adds all items to the ring buffer. Sets the expiration time if TTL is configured and also attempts to store the items
     * in the data store if one is configured.
     *
     * @param items items to be stored in the ring buffer and data store
     * @return the sequence id of the last item stored in the ring buffer
     * @throws HazelcastException                                              if there was any exception thrown by the data store
     * @throws com.hazelcast.nio.serialization.HazelcastSerializationException if the ring buffer is configured to keep items
     *                                                                         in object format and the item could not be
     *                                                                         deserialized
     */
public long addAll(Data[] items) {
    long firstSequence = -1;
    long lastSequence = -1;
    for (int i = 0; i < items.length; i++) {
        lastSequence = addInternal(items[i]);
        if (i == 0) {
            firstSequence = lastSequence;
        }
    }
    if (store.isEnabled() && items.length != 0) {
        try {
            store.storeAll(firstSequence, items);
        } catch (Exception e) {
            throw new HazelcastException(e);
        }
    }
    return lastSequence;
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) HazelcastException(com.hazelcast.core.HazelcastException) IOException(java.io.IOException) StaleSequenceException(com.hazelcast.ringbuffer.StaleSequenceException)

Aggregations

HazelcastException (com.hazelcast.core.HazelcastException)57 IOException (java.io.IOException)18 TxQueueItem (com.hazelcast.collection.impl.txnqueue.TxQueueItem)11 TransactionException (com.hazelcast.transaction.TransactionException)11 QuickTest (com.hazelcast.test.annotation.QuickTest)10 Test (org.junit.Test)10 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)8 ParallelTest (com.hazelcast.test.annotation.ParallelTest)8 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)8 File (java.io.File)8 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)7 OException (com.orientechnologies.common.exception.OException)7 OIOException (com.orientechnologies.common.io.OIOException)7 ODistributedRedirectException (com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException)7 OCallable (com.orientechnologies.common.util.OCallable)6 FileInputStream (java.io.FileInputStream)5 Callable (java.util.concurrent.Callable)5 Collator (com.hazelcast.mapreduce.Collator)4 CombinerFactory (com.hazelcast.mapreduce.CombinerFactory)4 Mapper (com.hazelcast.mapreduce.Mapper)4