Package org.apache.openejb.util

Examples of org.apache.openejb.util.Duration


    public void test() throws Exception {

        // To run in an IDE, uncomment and update this line
        System.setProperty("version", OpenEjbVersion.get().getVersion());

        final Duration reconnectDelay = new Duration("1 second");

        final File zip = Repository.getArtifact("org.apache.openejb", "openejb-standalone", "zip");
        final File app = Repository.getArtifact("org.apache.openejb.itests", "failover-ejb", "jar");

        final File dir = Files.tmpdir();

        System.setProperty("openejb.client.requestretry", "true");

        final Map<String, StandaloneServer> servers = new HashMap<String, StandaloneServer>();

        for (final String name : new String[]{"red", "green", "blue"}) {
            final File home = new File(dir, name);
            Files.mkdir(home);
            Zips.unzip(zip, home, true);

            final StandaloneServer server = new StandaloneServer(home, home);
            server.killOnExit();
            server.ignoreOut();
            server.getJvmOpts().add("-Dopenejb.classloader.forced-load=org.apache.openejb");
            server.getProperties().put("name", name);
            server.getProperties().put("openejb.extract.configuration", "false");

            IO.copy(app, Files.path(home, "apps", "itest.jar"));
            IO.copy(IO.read("<openejb><Deployments dir=\"apps/\"/></openejb>"), Files.path(home, "conf", "openejb.xml"));

            final StandaloneServer.ServerService ejbd = server.getServerService("ejbd");
            ejbd.setDisabled(false);
            ejbd.setBind("0.0.0.0");
            ejbd.setPort(getAvailablePort());
            ejbd.setThreads(5);
            ejbd.set("discoveryHost", "localhost");
            ejbd.set("discovery", "ejb:ejbd://{discoveryHost}:{port}/" + name);

            final StandaloneServer.ServerService multipoint = server.getServerService(MULTIPOINT);
            multipoint.setBind("0.0.0.0");
            multipoint.setPort(getAvailablePort());
            multipoint.setDisabled(false);
            multipoint.set("discoveryHost", "localhost");
            multipoint.set("discoveryName", name);
            multipoint.set("reconnectDelay", reconnectDelay.toString());

            servers.put(name, server);
        }

        final StandaloneServer red = servers.get("red");

        // Set all the initialServers to point to RED
        for (final Map.Entry<String, StandaloneServer> entry : servers.entrySet()) {
            final StandaloneServer server = entry.getValue();
            final StandaloneServer.ServerService multipoint = server.getServerService(MULTIPOINT);
            final String value = "lOcAlHosT:" + red.getServerService(MULTIPOINT).getPort() + ",locALHost:"+multipoint.getPort();
            multipoint.set("initialServers", value);
        }

        // Start all the servers except RED
        for (final Map.Entry<String, StandaloneServer> entry : servers.entrySet()) {
            if (entry.getKey().equals("red")) continue;
            entry.getValue().start(1, TimeUnit.MINUTES);
        }

        // Verify Failover is not yet functional

        {
            // RED was never started so BLUE never found any peers

            // Lets invoke BLUE then shut it down and verify we have
            // no other peers to invoke
            final StandaloneServer blue = servers.get("blue");
            final Properties environment = new Properties();
            environment.put(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
            environment.put(Context.PROVIDER_URL, "ejbd://localhost:" + blue.getServerService("ejbd").getPort());

            final InitialContext context = new InitialContext(environment);
            final Calculator bean = (Calculator) context.lookup("CalculatorBeanRemote");

            // Invoke BLUE a few times
            invoke(bean, 10, "blue");

            // Kill BLUE
            blue.kill();

            // Invocations should now fail (and not failover)
            try {
                bean.name();
                Assert.fail("Server should be down and failover not hooked up");
            } catch (final Exception e) {
                // pass
            }
        }

        // Now we start RED
        red.start(1, TimeUnit.MINUTES);

        // Wait for the reconnectDelay so GREEN can find RED
        Thread.sleep((long) (reconnectDelay.getTime(TimeUnit.MILLISECONDS) * 1.5));

        // Verify Failover is now functional

        {
            // RED was never started so GREEN never found any peers
View Full Code Here


    public synchronized long getTimeOut() {
        return timeOut;
    }

    private static long ms(final String durationValue, final TimeUnit defaultTU) {
        final Duration duration = new Duration(durationValue.trim());
        // default was minutes
        // let say the user uses as before "1" as value
        // time unit will be null so simply set the unit
        // to the "old" default
        if (duration.getUnit() == null) {
            duration.setUnit(defaultTU);
        }
        return duration.getUnit().toMillis(duration.getTime());
    }
View Full Code Here

            this.key = key;
            this.value = value;
            this.state = state;

            if (value instanceof Cache.TimeOut) {
                final Duration duration = ((Cache.TimeOut) value).getTimeOut();
                this.timeOut = duration != null ? duration.getTime(TimeUnit.MILLISECONDS) : getTimeOut();
            } else {
                this.timeOut = getTimeOut();
            }

            lastAccess = System.currentTimeMillis();
View Full Code Here

    public Duration getMaxWaitTime() {
        return maxWaitTime;
    }

    public DataSourceBuilder withMaxWaitTime(final long time, final TimeUnit unit) {
        return withMaxWaitTime(new Duration(time, unit));
    }
View Full Code Here

    public DataSourceBuilder withMaxWaitTime(final long time, final TimeUnit unit) {
        return withMaxWaitTime(new Duration(time, unit));
    }

    public void setMaxWaitTime(final long time, final TimeUnit unit) {
        setMaxWaitTime(new Duration(time, unit));
    }
View Full Code Here

    public Duration getTimeBetweenEvictionRuns() {
        return timeBetweenEvictionRuns;
    }

    public DataSourceBuilder withTimeBetweenEvictionRuns(final long time, final TimeUnit unit) {
        return withTimeBetweenEvictionRuns(new Duration(time, unit));
    }
View Full Code Here

    public DataSourceBuilder withTimeBetweenEvictionRuns(final long time, final TimeUnit unit) {
        return withTimeBetweenEvictionRuns(new Duration(time, unit));
    }

    public void setTimeBetweenEvictionRuns(final long time, final TimeUnit unit) {
        setTimeBetweenEvictionRuns(new Duration(time, unit));
    }
View Full Code Here

    public Duration getMinEvictableIdleTime() {
        return minEvictableIdleTime;
    }

    public DataSourceBuilder withMinEvictableIdleTime(final long time, final TimeUnit unit) {
        return withMinEvictableIdleTime(new Duration(time, unit));
    }
View Full Code Here

    public DataSourceBuilder withMinEvictableIdleTime(final long time, final TimeUnit unit) {
        return withMinEvictableIdleTime(new Duration(time, unit));
    }

    public void setMinEvictableIdleTime(final long time, final TimeUnit unit) {
        setMinEvictableIdleTime(new Duration(time, unit));
    }
View Full Code Here

    public Duration getAccessTimeout() {
        return accessTimeout;
    }

    public SingletonContainerBuilder withAccessTimeout(final long time, final TimeUnit unit) {
        return withAccessTimeout(new Duration(time, unit));
    }
View Full Code Here

TOP

Related Classes of org.apache.openejb.util.Duration

Copyright © 2018 www.massapicom. 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.