Java tutorial
package org.qcri.da.sysrev; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import org.apache.thrift.server.TServer; import org.apache.thrift.server.TThreadPoolServer; import org.apache.thrift.transport.TServerSocket; import org.apache.thrift.transport.TServerTransport; public class Server { public static ServerHandler handler; public static SysRevJavaHelpers.Processor<ServerHandler> processor; private static final Integer DEFAULT_PORT = 9090; public static void main(String[] args) { try { handler = new ServerHandler(); processor = new SysRevJavaHelpers.Processor<ServerHandler>(handler); final Integer port = args.length > 0 ? Integer.parseInt(args[0]) : DEFAULT_PORT; Runnable simple = new Runnable() { public void run() { simple(processor, port); } }; new Thread(simple).start(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } public static void simple(SysRevJavaHelpers.Processor<ServerHandler> processor, Integer port) { try { TServerTransport serverTransport = new TServerSocket(port.intValue()); // TServer server = new TSimpleServer(new Args(serverTransport).processor(processor)); // Use this for a multithreaded server // default for Args is minThreadCount: 5 and maxThreadCount: Integer.MAX_VALUE TServer server = new TThreadPoolServer( new TThreadPoolServer.Args(serverTransport).processor(processor)); System.out.println("Server listening on port " + port + "..."); server.serve(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } }