Search in sources :

Example 21 with HazelcastException

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

the class XmlClientConfigLocator method loadSystemPropertyFileResource.

private void loadSystemPropertyFileResource(String configSystemProperty) {
    //it is a file.
    File configurationFile = new File(configSystemProperty);
    LOGGER.info("Using configuration file at " + configurationFile.getAbsolutePath());
    if (!configurationFile.exists()) {
        String msg = "Config file at '" + configurationFile.getAbsolutePath() + "' doesn't exist.";
        throw new HazelcastException(msg);
    }
    try {
        in = new FileInputStream(configurationFile);
    } catch (FileNotFoundException e) {
        throw new HazelcastException("Failed to open file: " + configurationFile.getAbsolutePath(), e);
    }
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 22 with HazelcastException

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

the class DefaultAddressPicker method getPublicAddressByPortSearch.

private AddressDefinition getPublicAddressByPortSearch() throws IOException {
    NetworkConfig networkConfig = config.getNetworkConfig();
    boolean bindAny = hazelcastProperties.getBoolean(GroupProperty.SOCKET_SERVER_BIND_ANY);
    Throwable error = null;
    ServerSocket serverSocket = null;
    InetSocketAddress inetSocketAddress;
    boolean reuseAddress = networkConfig.isReuseAddress();
    logger.finest("inet reuseAddress:" + reuseAddress);
    int port = networkConfig.getPort();
    // port = 0 means system will pick up an ephemeral port.
    int portTrialCount = port > 0 && networkConfig.isPortAutoIncrement() ? networkConfig.getPortCount() : 1;
    AddressDefinition bindAddressDef = pickAddressDef();
    if (port == 0) {
        logger.info("No explicit port is given, system will pick up an ephemeral port.");
    }
    for (int i = 0; i < portTrialCount; i++) {
        /*
             * Instead of reusing the ServerSocket/ServerSocketChannel, we are going to close and replace them on
             * every attempt to find a free port. The reason to do this is because in some cases, when concurrent
             * threads/processes try to acquire the same port, the ServerSocket gets corrupted and isn't able to
             * find any free port at all (no matter if there are more than enough free ports available). We have
             * seen this happening on Linux and Windows environments.
             */
        serverSocketChannel = ServerSocketChannel.open();
        serverSocket = serverSocketChannel.socket();
        serverSocket.setReuseAddress(reuseAddress);
        serverSocket.setSoTimeout(SOCKET_TIMEOUT_MILLIS);
        try {
            if (bindAny) {
                inetSocketAddress = new InetSocketAddress(port + i);
            } else {
                inetSocketAddress = new InetSocketAddress(bindAddressDef.inetAddress, port + i);
            }
            logger.fine("Trying to bind inet socket address: " + inetSocketAddress);
            serverSocket.bind(inetSocketAddress, SOCKET_BACKLOG_LENGTH);
            logger.fine("Bind successful to inet socket address: " + serverSocket.getLocalSocketAddress());
            break;
        } catch (Exception e) {
            serverSocket.close();
            serverSocketChannel.close();
            error = e;
        }
    }
    if (serverSocket == null || !serverSocket.isBound()) {
        String message;
        if (networkConfig.isPortAutoIncrement()) {
            message = "ServerSocket bind has failed. Hazelcast cannot start. config-port: " + networkConfig.getPort() + ", latest-port: " + (port + portTrialCount);
        } else {
            message = "Port [" + port + "] is already in use and auto-increment is disabled." + " Hazelcast cannot start.";
        }
        throw new HazelcastException(message, error);
    }
    // get the actual port that's bound by server socket
    port = serverSocket.getLocalPort();
    serverSocketChannel.configureBlocking(false);
    bindAddress = createAddress(bindAddressDef, port);
    logger.info("Picked " + bindAddress + ", using socket " + serverSocket + ", bind any local is " + bindAny);
    return getPublicAddress(port);
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) InetSocketAddress(java.net.InetSocketAddress) NetworkConfig(com.hazelcast.config.NetworkConfig) ServerSocket(java.net.ServerSocket) SocketException(java.net.SocketException) HazelcastException(com.hazelcast.core.HazelcastException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 23 with HazelcastException

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

the class IncrementCommandProcessor method handle.

@Override
public void handle(IncrementCommand incrementCommand) {
    String key;
    try {
        key = URLDecoder.decode(incrementCommand.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);
    }
    try {
        textCommandService.lock(mapName, key);
    } catch (Exception e) {
        incrementCommand.setResponse(NOT_FOUND);
        if (incrementCommand.shouldReply()) {
            textCommandService.sendResponse(incrementCommand);
        }
        return;
    }
    incrementUnderLock(incrementCommand, key, mapName);
    textCommandService.unlock(mapName, key);
    if (incrementCommand.shouldReply()) {
        textCommandService.sendResponse(incrementCommand);
    }
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HazelcastException(com.hazelcast.core.HazelcastException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 24 with HazelcastException

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

the class ObjectMultiMapProxy method aggregate.

@Override
public <SuppliedValue, Result> Result aggregate(Supplier<K, V, SuppliedValue> supplier, Aggregation<K, SuppliedValue, Result> aggregation, JobTracker jobTracker) {
    try {
        isNotNull(jobTracker, "jobTracker");
        KeyValueSource<K, V> keyValueSource = KeyValueSource.fromMultiMap(this);
        Job<K, V> job = jobTracker.newJob(keyValueSource);
        Mapper mapper = aggregation.getMapper(supplier);
        CombinerFactory combinerFactory = aggregation.getCombinerFactory();
        ReducerFactory reducerFactory = aggregation.getReducerFactory();
        Collator collator = aggregation.getCollator();
        MappingJob mappingJob = job.mapper(mapper);
        ReducingSubmittableJob reducingJob;
        if (combinerFactory != null) {
            reducingJob = mappingJob.combiner(combinerFactory).reducer(reducerFactory);
        } else {
            reducingJob = mappingJob.reducer(reducerFactory);
        }
        ICompletableFuture<Result> future = reducingJob.submit(collator);
        return future.get();
    } catch (Exception e) {
        throw new HazelcastException(e);
    }
}
Also used : MappingJob(com.hazelcast.mapreduce.MappingJob) HazelcastException(com.hazelcast.core.HazelcastException) ReducerFactory(com.hazelcast.mapreduce.ReducerFactory) HazelcastException(com.hazelcast.core.HazelcastException) Collator(com.hazelcast.mapreduce.Collator) CombinerFactory(com.hazelcast.mapreduce.CombinerFactory) Mapper(com.hazelcast.mapreduce.Mapper) ReducingSubmittableJob(com.hazelcast.mapreduce.ReducingSubmittableJob)

Example 25 with HazelcastException

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

the class IOUtil method copyDirectory.

private static void copyDirectory(File source, File target) {
    if (target.exists() && !target.isDirectory()) {
        throw new IllegalArgumentException("Cannot copy source directory since the target already exists " + "but it is not a directory");
    }
    final File targetSubDir = new File(target, source.getName());
    if (!targetSubDir.exists() && !targetSubDir.mkdirs()) {
        throw new HazelcastException("Could not create the target directory " + target);
    }
    final File[] sourceFiles = source.listFiles();
    if (sourceFiles == null) {
        throw new HazelcastException("Error occurred while listing directory contents for copy");
    }
    for (File file : sourceFiles) {
        copy(file, targetSubDir);
    }
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) File(java.io.File)

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