Package client

Source Code of client.ConcurrentTaskRunner

/*
* Copyright 2013 Alexander Bartash <AlexanderBartash@mail.ru>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package client;

import client.tasks.BruteForceMD5;
import java.math.BigInteger;
import java.security.Policy;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*
* @author Alexander Bartash <AlexanderBartash@mail.ru>
* @version 06.03.2013 1:14:51
*/
public class ConcurrentTaskRunner {

    private static final Logger LOG = LoggerFactory.getLogger(ConcurrentTaskRunner.class);
    private static final String URL = "rmi://localhost/Compute";
    private static final String CONFIG_FILE = "rmi.policy";
    private static final int THREADS_COUNT = 7;
    /** Digest of the 500 000 000. */
    private static byte[] DIGEST = new BigInteger("a1630c86c52f617eb2fcca2754473fb", 16).toByteArray();

    public static void main(String args[]) {
        System.setProperty("java.security.policy", CONFIG_FILE);
        Policy.getPolicy().refresh();
        if (System.getSecurityManager() == null) {
            System.setSecurityManager(new SecurityManager());
        }

        final ExecutorService executorService = Executors.newFixedThreadPool(THREADS_COUNT);
        for (int i = 0; i < THREADS_COUNT; i++) {
            final BruteForceMD5 forceMD5Task = new BruteForceMD5(BigInteger.ZERO, null, THREADS_COUNT, i, DIGEST);
            executorService.submit(new RemoteTask(URL, forceMD5Task));
        }

        try {
            executorService.shutdown();
            executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
        } catch (InterruptedException ex) {
            LOG.error("Can't wait for the task result, an error occured.", ex);
        }
    }
}
TOP

Related Classes of client.ConcurrentTaskRunner

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.