Search in sources :

Example 11 with PostConstruct

use of javax.annotation.PostConstruct in project javaee7-samples by javaee-samples.

the class PersonSessionBean method initDB.

@PostConstruct
private void initDB() {
    try {
        // Get an instance of Couchbase
        List<URI> hosts = Arrays.asList(new URI("http://localhost:8091/pools"));
        // Get an instance of Couchbase
        // Name of the Bucket to connect to
        String bucket = "default";
        // Password of the bucket (empty) string if none
        String password = "";
        // Connect to the Cluster
        client = new CouchbaseClient(hosts, bucket, password);
    } catch (URISyntaxException | IOException ex) {
        Logger.getLogger(PersonSessionBean.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) CouchbaseClient(com.couchbase.client.CouchbaseClient) PostConstruct(javax.annotation.PostConstruct)

Example 12 with PostConstruct

use of javax.annotation.PostConstruct in project javaee7-samples by javaee-samples.

the class SubscriptionCreator method createSubscription.

/**
     * We create the subscription at soonest possible time after deployment so we
     * wouldn't miss any message
     */
@PostConstruct
void createSubscription() {
    try (JMSContext jms = factory.createContext()) {
        // <1> This is factory with clientId specified
        // <2> creates durable subscription on the topic
        JMSConsumer consumer = jms.createDurableConsumer(topic, Resources.SUBSCRIPTION);
        consumer.close();
    }
}
Also used : JMSConsumer(javax.jms.JMSConsumer) JMSContext(javax.jms.JMSContext) PostConstruct(javax.annotation.PostConstruct)

Example 13 with PostConstruct

use of javax.annotation.PostConstruct in project NabAlive by jcheype.

the class ApplicationGroovyLoader method init.

@PostConstruct
public void init() {
    File scriptFolder = new File(APPS_FOLDER);
    if (!scriptFolder.isDirectory()) {
        throw new IllegalStateException("parameter \"apps.folder\" must point to a directory: " + APPS_FOLDER);
    }
    Runnable folderWatcher = new FolderWatcher(scriptFolder) {

        @Override
        protected void onChange(File file) {
            logger.debug("FolderWatcher onChange: {}", file.getName());
            if (!file.exists()) {
                applicationManager.unRegisterByName(stripExtension(file.getName()));
                return;
            } else if (file.getName().endsWith(".zip")) {
                try {
                    registerZip(file);
                } catch (Exception e) {
                    logger.error("cannot load app: {}", file.getName(), e);
                }
            }
        }
    };
    new Thread(folderWatcher).start();
}
Also used : File(java.io.File) BeansException(org.springframework.beans.BeansException) IOException(java.io.IOException) FolderWatcher(com.nabalive.application.core.util.FolderWatcher) PostConstruct(javax.annotation.PostConstruct)

Example 14 with PostConstruct

use of javax.annotation.PostConstruct in project javaee7-samples by javaee-samples.

the class EmployeeBean method postConstruct.

@PostConstruct
public void postConstruct() {
    try {
        Context context = new InitialContext();
        em = (EntityManager) context.lookup("java:comp/env/persistence/myJNDI");
    } catch (NamingException ex) {
        Logger.getLogger(EmployeeBean.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) PersistenceContext(javax.persistence.PersistenceContext) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext) PostConstruct(javax.annotation.PostConstruct)

Example 15 with PostConstruct

use of javax.annotation.PostConstruct in project NabAlive by jcheype.

the class ChorController method init.

@PostConstruct
void init() {
    restHandler.get(new Route("/api/chor") {

        @Override
        public void handle(Request request, Response response, Map<String, String> map) throws Exception {
            String chor = checkNotNull(request.getParam("data"));
            int loop = Integer.parseInt(firstNonNull(request.getParam("loop"), "1"));
            ChorBuilder chorBuilder = new ChorBuilder(chor, loop);
            response.write(chorBuilder.build());
        }
    }).get(new Route("/api/chor/ears") {

        @Override
        public void handle(Request request, Response response, Map<String, String> map) throws Exception {
            ChorBuilder chorBuilder = new ChorBuilder();
            String left = request.getParam("left");
            String right = request.getParam("right");
            if (left != null) {
                int val = Integer.parseInt(left);
                chorBuilder.setEar((byte) 0, (byte) (val > 0 ? 0 : 1), (byte) Math.abs(val));
            }
            if (right != null) {
                int val = Integer.parseInt(right);
                chorBuilder.setEar((byte) 1, (byte) (val > 0 ? 0 : 1), (byte) Math.abs(val));
            }
            response.write(chorBuilder.build());
        }
    }).get(new Route("/api/chor/led/:led/:color") {

        @Override
        public void handle(Request request, Response response, Map<String, String> map) throws Exception {
            ChorBuilder chorBuilder = new ChorBuilder();
            String color = checkNotNull(map.get("color"));
            int led = Integer.parseInt(checkNotNull(map.get("led")));
            chorBuilder.setLed((byte) led, color);
            response.write(chorBuilder.build());
        }
    }).get(new Route("/api/chor/rand/:time") {

        @Override
        public void handle(Request request, Response response, Map<String, String> map) throws Exception {
            int time = Integer.parseInt(map.get("time"));
            Random rand = new Random();
            ChorBuilder chorBuilder = new ChorBuilder();
            for (int t = 0; t < time; t++) {
                for (int led = 0; led < 5; led++) if (rand.nextBoolean()) {
                    chorBuilder.setLed((byte) led, (byte) rand.nextInt(), (byte) rand.nextInt(), (byte) rand.nextInt());
                }
                if (t % 10 == 0) {
                    if (rand.nextBoolean()) {
                        chorBuilder.setEar((byte) 0, (byte) (rand.nextBoolean() ? 0 : 1), (byte) rand.nextInt(0x4));
                    }
                    if (rand.nextBoolean()) {
                        chorBuilder.setEar((byte) 1, (byte) (rand.nextBoolean() ? 0 : 1), (byte) rand.nextInt(0x4));
                    }
                }
                chorBuilder.waitChor(1);
            }
            chorBuilder.setEar((byte) 1, (byte) 0, (byte) 0);
            chorBuilder.setEar((byte) 0, (byte) 0, (byte) 0);
            response.write(chorBuilder.build());
        }
    });
}
Also used : Response(com.nabalive.framework.web.Response) Random(java.util.Random) Request(com.nabalive.framework.web.Request) ChorBuilder(com.nabalive.server.web.ChorBuilder) Map(java.util.Map) Route(com.nabalive.framework.web.Route) PostConstruct(javax.annotation.PostConstruct)

Aggregations

PostConstruct (javax.annotation.PostConstruct)194 IOException (java.io.IOException)24 File (java.io.File)16 SamlRegisteredService (org.apereo.cas.support.saml.services.SamlRegisteredService)16 Map (java.util.Map)13 ExternalResource (com.vaadin.server.ExternalResource)11 ArrayList (java.util.ArrayList)11 Label (com.vaadin.ui.Label)8 VerticalLayout (com.vaadin.ui.VerticalLayout)8 HashMap (java.util.HashMap)8 Request (com.nabalive.framework.web.Request)7 Response (com.nabalive.framework.web.Response)7 Route (com.nabalive.framework.web.Route)7 Link (com.vaadin.ui.Link)7 Properties (java.util.Properties)6 InitialContext (javax.naming.InitialContext)6 IStatus (org.eclipse.core.runtime.IStatus)5 URISyntaxException (java.net.URISyntaxException)4 Logger (org.slf4j.Logger)4 StatusLineWriter (alma.acs.eventbrowser.status.StatusLineWriter)3