Example usage for java.rmi.registry Registry REGISTRY_PORT

List of usage examples for java.rmi.registry Registry REGISTRY_PORT

Introduction

In this page you can find the example usage for java.rmi.registry Registry REGISTRY_PORT.

Prototype

int REGISTRY_PORT

To view the source code for java.rmi.registry Registry REGISTRY_PORT.

Click Source Link

Document

Well known port for registry.

Usage

From source file:com.feedzai.fos.api.config.FosConfig.java

/**
 * Creates a new instance of the {@link FosConfig} class.
 *
 * @param configuration The base configuration to use.
 *//*from  ww  w .  jav a  2 s.  c om*/
public FosConfig(Configuration configuration) {
    checkNotNull(configuration, "Configuration cannot be null.");
    checkArgument(configuration.containsKey(FACTORY_NAME),
            "The configuration parameter " + FACTORY_NAME + " should be defined.");
    this.config = configuration;
    this.embeddedRegistry = configuration.getBoolean(EMBEDDED_REGISTRY, false);
    this.registryPort = configuration.getInt(REGISTRY_PORT, Registry.REGISTRY_PORT);
    this.factoryName = configuration.getString(FACTORY_NAME);
    this.headerLocation = configuration.getString(HEADER_LOCATION, "models");
    this.threadPoolSize = configuration.getInt(THREADPOOL_SIZE, 20);
    this.scoringPort = configuration.getInt(SCORING_PORT, DEFAULT_SCORING_PORT);
}

From source file:de.tudarmstadt.lt.lm.app.StartLM.java

@SuppressWarnings("static-access")
public StartLM(String[] args) {
    Options opts = new Options();
    opts.addOption(new Option("?", "help", false, "display this message"));
    opts.addOption(OptionBuilder.withLongOpt("host").withArgName("hostname").hasArg()
            .withDescription("specifies the hostname on which the rmi registry listens (default: localhost)")
            .create("h"));
    opts.addOption(OptionBuilder.withLongOpt("rmiport").withArgName("port-number").hasArg()
            .withDescription(String.format("specifies the port on which rmi registry listens (default: %d)",
                    Registry.REGISTRY_PORT))
            .create("rp"));
    opts.addOption(OptionBuilder.withLongOpt("port").withArgName("port-number").hasArg().withDescription(
            "specifies the port on which this service should populate (default: 0, which means a random port will be assigned)")
            .create("p"));
    opts.addOption(OptionBuilder.withLongOpt("lmtype").withArgName("class").hasArg().withDescription(
            "specify the instance of the language model that you want to use: {BerkeleyLM, CountingLM, LaplaceSmoothedLM, CountingStringLM, KneserNeyLM, (experimental: KneserNeyLMRecursive, PoptKneserNeyLMRecursive, ModifiedKNeserNeyLMRecursive)} (default: BerkeleyLM)")
            .create("t"));
    opts.addOption(OptionBuilder.withLongOpt("ptype").withArgName("class").hasArg().withDescription(
            "specify the instance of the language model provider that you want to use: {LtSegProvider, BreakIteratorStringProvider, PreTokenizedStringProvider} (default: LtSegProvider)")
            .create("pt"));
    opts.addOption(OptionBuilder.withLongOpt("dir").withArgName("directory").isRequired().hasArg()
            .withDescription(/*from   w  ww .  j av  a 2 s  .  c o  m*/
                    "specify the directory that contains '.txt' files that are used as source for this language model")
            .create("d"));
    opts.addOption(OptionBuilder.withLongOpt("order").withArgName("ngram-order").hasArg()
            .withDescription("specify the order for this language model").create("n"));
    opts.addOption(OptionBuilder.withLongOpt("identifier").withArgName("name").hasArg().withDescription(
            "specify a name/identifier for the language model. If no name is given, a random name will be generated.")
            .create("i"));
    opts.addOption(OptionBuilder.withLongOpt("overwrite")
            .withDescription("Overwrite existing saved or temporary files.").create("w"));
    opts.addOption(OptionBuilder.withLongOpt("discount").withArgName("Discount value in [0,1]").hasArg()
            .withDescription("Uniform discount value for Lucene based Kneser-Ney LM.").create());
    opts.addOption(OptionBuilder.withLongOpt("mincount").withArgName("int").hasArg().withDescription(
            "(Only applicable for Lucene Based LMs) - Specify the number of times an ngram must occur to be considered in further calculations. Ngrams with counts below mincount are filtered. (default: 1).")
            .create("m"));

    try {
        CommandLine cmd = new ExtendedGnuParser(true).parse(opts, args);
        if (cmd.hasOption("help"))
            CliUtils.print_usage_quit(System.err, StartLM.class.getSimpleName(), opts, USAGE_HEADER, null, 0);

        _rmiRegistryPort = Integer
                .parseInt(cmd.getOptionValue("rmiport", String.valueOf(Registry.REGISTRY_PORT)));
        _port = Integer.parseInt(cmd.getOptionValue("port", "0"));
        _srcdir = cmd.getOptionValue("dir");
        _n = Integer.parseInt(cmd.getOptionValue("order", "5"));
        _type_lm = cmd.getOptionValue("lmtype", BerkeleyLM.class.getSimpleName());
        _type_provider = cmd.getOptionValue("ptype", LtSegProvider.class.getSimpleName());
        _name = cmd.getOptionValue("identifier", String.valueOf(System.currentTimeMillis()));
        _host = cmd.getOptionValue("host", "localhost");
        _overwrite = cmd.hasOption("overwrite");
        _discount = Double.parseDouble(cmd.getOptionValue("discount", "-1"));
        _mincount = Integer.parseInt(cmd.getOptionValue("mincount", "1"));
        // String[] non_named_args = cmd.getArgs();
        _providerJmxBeanName = new ObjectName("de.tudarmstadt.lt.lm:type=ProviderService");

    } catch (Exception e) {
        LOG.error("{}: {}", e.getClass().getSimpleName(), e.getMessage());
        CliUtils.print_usage_quit(System.err, StartLM.class.getSimpleName(), opts, USAGE_HEADER,
                String.format("%s: %s%n", e.getClass().getSimpleName(), e.getMessage()), 1);
    }
}

From source file:com.mindquarry.jcr.jackrabbit.JackrabbitRMIRepositoryStandalone.java

private void start(CommandLine line) throws Exception {
    String repoConf;//from  ww  w . ja  v  a 2  s  .co  m
    String repoConfArg = line.getOptionValue(O_CONF);
    if (null == repoConfArg)
        repoConf = createDefaultRepoConf();
    else
        repoConf = new File(repoConfArg).getAbsolutePath();

    File repoLoc = new File(line.getOptionValue(O_LOC));
    if (!repoLoc.exists()) {
        repoLoc.mkdir();
    }
    if (!repoLoc.isDirectory()) {
        throw new IllegalArgumentException("Repository location is not a directory.");
    }
    Repository repo = new TransientRepository(repoConf, repoLoc.getAbsolutePath());

    ServerAdapterFactory factory = new ServerAdapterFactory();
    RemoteRepository remoteRepo = factory.getRemoteRepository(repo);

    reg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
    reg.rebind(REMOTE_REPO_NAME, remoteRepo);

    String workspace = line.getOptionValue(O_WS);
    if (null == workspace)
        workspace = "default";

    session = repo.login(
            new SimpleCredentials(line.getOptionValue(O_USER), line.getOptionValue(O_PWD).toCharArray()),
            workspace);

    InputStream nodeTypeDefIn = getClass().getResourceAsStream(MQ_JCR_XML_NODETYPES_FILE);

    JackrabbitInitializerHelper.setupRepository(session, new InputStreamReader(nodeTypeDefIn),
            MQ_JCR_XML_NODETYPES_FILE);
    session.save();
}

From source file:org.alfresco.reporting.test.TestReporting.java

private static Registry startRegistry() throws RemoteException {
    System.out.println("enter startRegistry");
    Registry registry = null;//from   w ww. j ava 2  s  .  c o  m
    try {
        registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
        System.out.println("exit startRegistry: RMI registry created.");
    } catch (ExportException e) {
        System.out.println("exit startRegistry: RMI registry already existed.");
    }
    return registry;
}

From source file:org.alfresco.reporting.test.TestReporting.java

private static InitialContext createContext() throws NamingException {
    Properties env = new Properties();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
    env.put(Context.PROVIDER_URL, "rmi://localhost:" + Registry.REGISTRY_PORT);
    InitialContext context = new InitialContext(env);
    return context;
}

From source file:org.apache.jcs.auxiliary.remote.RemoteCacheManager.java

/**
 * Returns an instance of RemoteCacheManager for the given connection parameters.
 * <p>/*www  . j a  v  a  2  s  .  c o  m*/
 * Host and Port uniquely identify a manager instance.
 * <p>
 * Also starts up the monitoring daemon, if not already started.
 * <p>
 * If the connection cannot be established, zombie objects will be used for future recovery
 * purposes.
 * <p>
 * @param cattr
 * @param cacheMgr
 * @return The instance value
 * @parma port port of the registry.
 */
public static RemoteCacheManager getInstance(IRemoteCacheAttributes cattr, ICompositeCacheManager cacheMgr) {
    String host = cattr.getRemoteHost();
    int port = cattr.getRemotePort();
    String service = cattr.getRemoteServiceName();
    if (host == null) {
        host = "";
    }
    if (port < 1024) {
        port = Registry.REGISTRY_PORT;
    }
    Location loc = new Location(host, port);

    RemoteCacheManager ins = (RemoteCacheManager) instances.get(loc);
    synchronized (instances) {
        if (ins == null) {
            ins = (RemoteCacheManager) instances.get(loc);
            if (ins == null) {
                // cahnge to use cattr and to set defaults
                ins = new RemoteCacheManager(host, port, service, cacheMgr);
                ins.irca = cattr;
                instances.put(loc, ins);
            }
        }
    }

    ins.clients++;
    // Fires up the monitoring daemon.
    if (monitor == null) {
        monitor = RemoteCacheMonitor.getInstance();
        // If the returned monitor is null, it means it's already started
        // elsewhere.
        if (monitor != null) {
            Thread t = new Thread(monitor);
            t.setDaemon(true);
            t.start();
        }
    }
    return ins;
}

From source file:org.apache.jcs.auxiliary.remote.RemoteUtils.java

/**
 * Creates and exports a registry on the specified port of the local host.
 * <p>/*  w  ww  .  j  ava  2  s.c om*/
 * @param port
 * @return the port the registry was started on
 * @throws RemoteException
 */
public static int createRegistry(int port) throws RemoteException {
    if (log.isInfoEnabled()) {
        log.info("createRegistry> setting security manager");
    }
    System.setSecurityManager(new RMISecurityManager());

    if (port < 1024) {
        if (log.isInfoEnabled()) {
            log.info("Port chosen was less than 1024, will use default [" + Registry.REGISTRY_PORT
                    + "] instead.");
        }
        port = Registry.REGISTRY_PORT;
    }

    if (log.isInfoEnabled()) {
        log.info("createRegistry> creating registry on port [" + port + "]");
    }
    LocateRegistry.createRegistry(port);
    return port;
}

From source file:org.apache.jcs.auxiliary.remote.server.RemoteCacheServer.java

/**
 * Shuts down the remote server.//from   w ww  .j a v a  2  s . com
 * <p>
 * @throws IOException
 */
public void shutdown() throws IOException {
    RemoteCacheServerFactory.shutdownImpl("", Registry.REGISTRY_PORT);
}

From source file:org.apache.jcs.auxiliary.remote.server.RemoteCacheServerFactory.java

/**
 * Creates an local RMI registry on the default port, starts up the remote cache server, and
 * binds it to the registry.//from www.  j a  v a2  s.c  o m
 * A remote cache is either a local cache or a cluster cache
 * @param args The command line arguments
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    Properties prop = args.length > 0 ? RemoteUtils.loadProps(args[args.length - 1]) : new Properties();

    int port;
    try {
        port = Integer.parseInt(prop.getProperty("registry.port"));
    } catch (NumberFormatException ex) {
        port = Registry.REGISTRY_PORT;
    }

    // shutdown
    if (args.length > 0 && args[0].toLowerCase().indexOf("-shutdown") != -1) {
        String serviceName = prop.getProperty(REMOTE_CACHE_SERVICE_NAME, REMOTE_CACHE_SERVICE_VAL).trim();
        String registry = "//:" + port + "/" + serviceName;

        if (log.isDebugEnabled()) {
            log.debug("looking up server " + registry);
        }
        Object obj = Naming.lookup(registry);
        if (log.isDebugEnabled()) {
            log.debug("server found");
        }
        IRemoteCacheServiceAdmin admin = (IRemoteCacheServiceAdmin) obj;
        try {
            admin.shutdown();
        } catch (Exception ex) {
            log.error("Problem calling shutdown.", ex);
        }
        log.debug("done.");
        System.exit(0);
    }

    // STATS
    if (args.length > 0 && args[0].toLowerCase().indexOf("-stats") != -1) {

        log.debug("getting cache stats");

        try {
            String serviceName = prop.getProperty(REMOTE_CACHE_SERVICE_NAME, REMOTE_CACHE_SERVICE_VAL).trim();
            String registry = "//:" + port + "/" + serviceName;
            log.debug("looking up server " + registry);
            Object obj = Naming.lookup(registry);
            log.debug("server found");

            log.debug("obj = " + obj);
            IRemoteCacheServiceAdmin admin = (IRemoteCacheServiceAdmin) obj;

            try {
                System.out.println(admin.getStats().toString());
                log.debug(admin.getStats());
            } catch (Exception es) {
                log.error(es);
            }

        } catch (Exception ex) {
            log.error("Problem getting stats.", ex);
        }
        log.debug("done.");
        System.exit(0);
    }

    // startup.
    String host = prop.getProperty("registry.host");

    if (host == null || host.trim().equals("") || host.trim().equals("localhost")) {
        log.debug("main> creating registry on the localhost");
        port = RemoteUtils.createRegistry(port);
    }
    log.debug("main> starting up RemoteCacheServer");
    RemoteCacheServerFactory.startup(host, port, args.length > 0 ? args[0] : null);
    log.debug("main> done");
}

From source file:org.ops4j.pax.exam.container.def.internal.PaxRunnerTestContainer.java

/**
 * Creates an RMI registry on the first free port found.
 *
 * @return RMI registry/*from   ww w.j  a  v  a 2 s .  c om*/
 */
protected int createRegistry() {
    for (int port = Registry.REGISTRY_PORT; port <= Registry.REGISTRY_PORT + AMOUNT_OF_PORTS_TO_CHECK; port++) {
        try {
            m_registry = LocateRegistry.createRegistry(port);
            LOG.info("RMI registry started on port [" + port + "]");
            return port;
        } catch (Exception e) {
            // ignore and try next port number
        }
    }

    throw new RuntimeException("No free port in range " + Registry.REGISTRY_PORT + ":" + Registry.REGISTRY_PORT
            + AMOUNT_OF_PORTS_TO_CHECK);
}