Example usage for java.lang Integer valueOf

List of usage examples for java.lang Integer valueOf

Introduction

In this page you can find the example usage for java.lang Integer valueOf.

Prototype

@HotSpotIntrinsicCandidate
public static Integer valueOf(int i) 

Source Link

Document

Returns an Integer instance representing the specified int value.

Usage

From source file:org.eclipse.swt.examples.accessibility.AccessibleValueExample.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.setText("Accessible Value Example");

    final Canvas canvas = new Canvas(shell, SWT.DOUBLE_BUFFERED);
    canvas.addPaintListener(e -> {/*ww  w. jav  a2 s  .  c  o  m*/
        Rectangle rect = canvas.getClientArea();
        String val = String.valueOf(value);
        Point size = e.gc.stringExtent(val);
        e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_LIST_SELECTION));
        e.gc.fillRectangle(0, 0, rect.width * value / (max - min), rect.height);
        e.gc.drawString(val, rect.x + (rect.width - size.x) / 2, rect.y + (rect.height - size.y) / 2, true);
    });

    Accessible accessible = canvas.getAccessible();
    accessible.addAccessibleListener(new AccessibleAdapter() {
        @Override
        public void getName(AccessibleEvent e) {
            e.result = "The value of this canvas is " + value;
        }
    });
    accessible.addAccessibleControlListener(new AccessibleControlAdapter() {
        @Override
        public void getRole(AccessibleControlEvent e) {
            e.detail = ACC.ROLE_PROGRESSBAR;
        }
    });
    accessible.addAccessibleValueListener(new AccessibleValueAdapter() {
        @Override
        public void setCurrentValue(AccessibleValueEvent e) {
            value = e.value.intValue();
            canvas.redraw();
        }

        @Override
        public void getMinimumValue(AccessibleValueEvent e) {
            e.value = Integer.valueOf(min);
        }

        @Override
        public void getMaximumValue(AccessibleValueEvent e) {
            e.value = Integer.valueOf(max);
        }

        @Override
        public void getCurrentValue(AccessibleValueEvent e) {
            e.value = Integer.valueOf(value);
        }
    });

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:com.setronica.ucs.server.MessageServer.java

public static void main(String[] args) throws Exception {
    String hostname = System.getProperty("host", "localhost");
    String portStr = System.getProperty("port", "1985");
    Integer port = Integer.valueOf(portStr);
    String zkConnect = System.getProperty("zkConnect");

    if (zkConnect != null && zkConnect.length() > 0) {
        MessageServer server = new MessageServer();
        server.registerService(hostname, port, zkConnect);
    } else {//ww  w  .  j  a v a  2s.c  o m
        ClassPathXmlApplicationContext applicationContext = bootstrapMemory();
        EventLoop eventLoop = createMsgPackRPCServer(applicationContext, hostname, port);
        try {
            eventLoop.join();
        } catch (InterruptedException e) {
            eventLoop.shutdown();
            eventLoop.join();
        }
    }
}

From source file:com.martinlamas.dicomserver.DicomServer.java

public static void main(String[] args) {
    int port = DEFAULT_PORT;

    String aeTitle = DEFAULT_AE_TITLE;
    File storageDirectory = new File(DEFAULT_STORAGE_DIRECTORY);

    try {/*from www.j  a  va2s.  c o m*/
        CommandLine line = new DefaultParser().parse(getOptions(), args);

        if (line.hasOption("p"))
            port = Integer.valueOf(line.getOptionValue("p"));

        if (line.hasOption("d"))
            storageDirectory = new File(line.getOptionValue("d"));

        if (line.hasOption("t"))
            aeTitle = line.getOptionValue("t");

        List<DicomServerApplicationEntity> applicationEntities = new ArrayList<DicomServerApplicationEntity>();

        DicomServerApplicationEntity applicationEntity = new DicomServerApplicationEntity(aeTitle,
                storageDirectory);

        applicationEntities.add(applicationEntity);

        showBanner();

        IDicomStoreSCPServer server = new DicomStoreSCPServer(port, applicationEntities);
        server.start();
    } catch (ParseException e) {
        printUsage();
    } catch (Exception e) {
        logger.error("Unable to start DICOM server: " + e.getMessage());
        e.printStackTrace();
    }
}

From source file:com.sm.transport.grizzly.TestClient.java

public static void main(String[] args) throws Exception {
    String[] opts = new String[] { "-thread", "-times", "-host", "-port", "-size" };
    String[] defaults = new String[] { "2", "10", "localhost", "7120", "2000" };
    String[] paras = getOpts(args, opts, defaults);
    int threads = Integer.valueOf(paras[0]);
    int times = Integer.valueOf(paras[1]);
    String host = paras[2];//from   w  ww  .  j  a va  2  s  . co  m
    int port = Integer.valueOf(paras[3]);
    int size = Integer.valueOf(paras[4]);
    for (int i = 0; i < threads; i++) {
        logger.info("start thread # " + i);
        TCPClient client = createTCPClient(host, port);
        new Thread(new ClientThread(client, times, size)).start();
    }
    //System.exit(0);
}

From source file:com.continuuity.loom.runtime.DummyProvisioner.java

public static void main(final String[] args) throws Exception {
    Options options = new Options();
    options.addOption("h", "host", true, "Loom server to connect to");
    options.addOption("p", "port", true, "Loom server port to connect to");
    options.addOption("c", "concurrency", true, "default concurrent threads");
    options.addOption("f", "failurePercent", true, "% of the time a provisioner should fail its task");
    options.addOption("o", "once", false, "whether or not only one task should be taken before exiting");
    options.addOption("d", "taskDuration", true, "number of milliseconds it should take to finish a task");
    options.addOption("s", "sleepMs", true,
            "number of milliseconds a thread will sleep before taking another task");
    options.addOption("n", "numTasks", true,
            "number of tasks to try and take from the queue.  Default is infinite.");
    options.addOption("t", "tenant", true, "tenant id to use.");

    try {//from www .  jav a2  s.  c o  m
        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(options, args);
        host = cmd.hasOption('h') ? cmd.getOptionValue('h') : "localhost";
        port = cmd.hasOption('p') ? Integer.valueOf(cmd.getOptionValue('p')) : 55054;
        concurrency = cmd.hasOption('c') ? Integer.valueOf(cmd.getOptionValue('c')) : 5;
        failurePercent = cmd.hasOption('f') ? Integer.valueOf(cmd.getOptionValue('f')) : 0;
        runOnce = cmd.hasOption('o');
        taskMs = cmd.hasOption('d') ? Long.valueOf(cmd.getOptionValue('d')) : 1000;
        sleepMs = cmd.hasOption('s') ? Long.valueOf(cmd.getOptionValue('s')) : 1000;
        numTasks = cmd.hasOption('n') ? Integer.valueOf(cmd.getOptionValue('n')) : -1;
        tenant = cmd.hasOption('t') ? cmd.getOptionValue('t') : "loom";
    } catch (ParseException e) {
        LOG.error("exception parsing input arguments.", e);
        return;
    }
    if (concurrency < 1) {
        LOG.error("invalid concurrency level {}.", concurrency);
        return;
    }

    if (runOnce) {
        new Provisioner("dummy-0", tenant, host, port, failurePercent, taskMs, sleepMs, 1).runOnce();
    } else {
        LOG.info(String.format(
                "running with %d threads, connecting to %s:%d using tenant %s, with a failure rate of"
                        + "%d percent, task time of %d ms, and sleep time of %d ms between fetches",
                concurrency, host, port, tenant, failurePercent, taskMs, sleepMs));
        pool = Executors.newFixedThreadPool(concurrency);

        try {
            int tasksPerProvisioner = numTasks >= 0 ? numTasks / concurrency : -1;
            int extra = numTasks < 0 ? 0 : numTasks % concurrency;
            pool.execute(new Provisioner("dummy-0", tenant, host, port, failurePercent, taskMs, sleepMs,
                    tasksPerProvisioner + extra));
            for (int i = 1; i < concurrency; i++) {
                pool.execute(new Provisioner("dummy-" + i, tenant, host, port, failurePercent, taskMs, sleepMs,
                        tasksPerProvisioner));
            }
        } catch (Exception e) {
            LOG.error("Caught exception, shutting down now.", e);
            pool.shutdownNow();
        }
        pool.shutdown();
    }
}

From source file:com.vikram.kdtree.ElementalHttpServer.java

public static void main(String[] args) throws Exception {
    // Set up the HTTP protocol processor
    HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate())
            .add(new ResponseServer("Test/1.1")).add(new ResponseContent()).add(new ResponseConnControl())
            .build();//from   w w  w . j ava  2 s . co m

    // Set up request handlers
    UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper();
    reqistry.register("*", new HttpPostReceiver());

    // Set up the HTTP service
    HttpService httpService = new HttpService(httpproc, reqistry);

    Properties properties = new Properties();
    properties.load(new FileInputStream("Config.properties"));

    Thread t = new RequestListenerThread(Integer.valueOf(properties.getProperty("requestPort")), httpService,
            null);
    t.setDaemon(false);
    t.start();
}

From source file:com.bachelor.boulmier.workmaster.WorkMaster.java

public static void main(String[] args) throws IOException, InterruptedException {
    defineOptions();//from w  ww .  j  a  va  2 s .  c om
    CommandLineParser parser = new BasicParser();
    CommandLine cmd;
    try {
        cmd = parser.parse(options, args);

        if (cmd.hasOption(MasterConfig.CMD.CLILONGOPT)) {
            cliEnabled = true;
        }
        if (cmd.hasOption(MasterConfig.CMD.DEBUGLONGOPT)) {
            debug = true;
        }
        if (cmd.hasOption(MasterConfig.CMD.MAXVMLONGOPT)) {
            maxVM = Integer.valueOf(cmd.getOptionValue(MasterConfig.CMD.MAXVMLONGOPT));
        }
        if (cmd.hasOption(MasterConfig.CMD.VERBOSELONGOPT)) {
            verbose = true;
        }
        if (cmd.hasOption(MasterConfig.CMD.REMOTEWSLONGOPT)) {
            webServer = cmd.getOptionValue(MasterConfig.CMD.REMOTEWSLONGOPT);
            if (!MasterConfig.DEFAULT.IP_PORT_PATTERN.matcher(webServer).matches()) {
                throw new ParseException("Given IP:PORT does not match pattern");
            }
        }

        if (cmd.hasOption(MasterConfig.CMD.HELPLONGOPT)) {
            printHelp();
        }

        logger = LoggerFactory.getLogger();

        QueuingService.get()
                .send(RequestBuilder.builder().withExecutableName(ExecutableName.CAT)
                        .with(RequestProperty.CLIENT_EMAIL, "anthony.boulmier.cfpt@gmail.com")
                        .with(RequestProperty.JOB_IDENTIFIER, UUID.randomUUID().toString())
                        .with(RequestProperty.ARGS, "JobExecutor.log").create());
        Thread.sleep(3000);

    } catch (ParseException pe) {
        logger.error(pe.getMessage());
        printHelp();
    }

}

From source file:com.sm.transport.netty.TestEchoClient.java

public static void main(String[] args) throws Exception {
    String[] opts = new String[] { "-thread", "-times", "-host", "-port", "-size" };
    String[] defaults = new String[] { "2", "10", "localhost", "7120", "2000" };
    String[] paras = getOpts(args, opts, defaults);
    int threads = Integer.valueOf(paras[0]);
    int times = Integer.valueOf(paras[1]);
    String host = paras[2];/*from  w w w . ja va2s. c o m*/
    int size = Integer.valueOf(paras[4]);
    int port = Integer.valueOf(paras[3]);
    for (int i = 0; i < threads; i++) {
        logger.info("start thread # " + i);
        TCPClient client = createTCPClient(host, port);
        new Thread(new ClientThread(client, times, size)).start();
    }
    //System.exit(0);
}

From source file:com.sm.transport.TestClient.java

public static void main(String[] args) throws Exception {
    String[] opts = new String[] { "-thread", "-times", "-host", "-port", "-size" };
    String[] defaults = new String[] { "2", "10", "localhost", "7100", "20000" };
    String[] paras = getOpts(args, opts, defaults);
    int threads = Integer.valueOf(paras[0]);
    int times = Integer.valueOf(paras[1]);
    String host = paras[2];/*ww  w.  ja v  a 2s . co  m*/
    int size = Integer.valueOf(paras[4]);
    int port = Integer.valueOf(paras[3]);
    for (int i = 0; i < threads; i++) {
        logger.info("start thread # " + i);
        TCPClient client = createTCPClient(host, port);
        new Thread(new ClientThread(client, times, size)).start();
    }
    //System.exit(0);
}

From source file:ChatServer.java

public static void main(String[] args) {
    // DeviceUpdater du = new DeviceUpdater();
    int id = 0;//from  www .  j a  va2 s  .  com
    String host = "localhost";
    int port = 11001;
    if (args.length == 2) {
        host = args[0];
        port = Integer.valueOf(args[1]);
    }
    Socket sock;
    try {
        ServerSocket server = new ServerSocket(port);
        while (true) {
            // System.out.println("Server waiting for connects on port " + port);
            sock = server.accept();
            id++;
            ChatServer threadOfServer = new ChatServer(sock, id);
            threadOfServer.start();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}