Search in sources :

Example 6 with PostConstruct

use of javax.annotation.PostConstruct in project che by eclipse.

the class StackLoader method start.

/**
     * Load predefined stacks with their icons to the {@link StackDao}.
     */
@PostConstruct
public void start() {
    if (Files.exists(stackJsonPath) && Files.isRegularFile(stackJsonPath)) {
        try (BufferedReader reader = Files.newBufferedReader(stackJsonPath)) {
            List<StackImpl> stacks = GSON.fromJson(reader, new TypeToken<List<StackImpl>>() {
            }.getType());
            stacks.forEach(this::loadStack);
        } catch (Exception e) {
            LOG.error("Failed to store stacks ", e);
        }
    }
}
Also used : StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) TypeToken(com.google.gson.reflect.TypeToken) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) NotFoundException(org.eclipse.che.api.core.NotFoundException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) PostConstruct(javax.annotation.PostConstruct)

Example 7 with PostConstruct

use of javax.annotation.PostConstruct in project jetty.project by eclipse.

the class AnnotationTest method myPostConstructMethod.

@PostConstruct
private void myPostConstructMethod() {
    postConstructResult = "<span class=\"pass\">PASS</span>";
    try {
        dsResult = (myDS == null ? "<span class=\"fail\">FAIL</span>" : "<span class=\"pass\">myDS=" + myDS.toString() + "</span>");
    } catch (Exception e) {
        dsResult = "<span class=\"fail\">FAIL:</span> " + e;
    }
    envResult = (maxAmount == null ? "FAIL</span>" : "<span class=\"pass\">maxAmount=" + maxAmount.toString() + "</span>");
    try {
        InitialContext ic = new InitialContext();
        envLookupResult = "java:comp/env/com.acme.test.AnnotationTest/maxAmount=" + ic.lookup("java:comp/env/com.acme.test.AnnotationTest/maxAmount");
    } catch (Exception e) {
        envLookupResult = "<span class=\"fail\">FAIL:</span> " + e;
    }
    envResult2 = (minAmount == null ? "<span class=\"fail\">FAIL</span>" : "<span class=\"pass\">minAmount=" + minAmount.toString() + "</span>");
    try {
        InitialContext ic = new InitialContext();
        envLookupResult2 = "java:comp/env/someAmount=" + ic.lookup("java:comp/env/someAmount");
    } catch (Exception e) {
        envLookupResult2 = "<span class=\"fail\">FAIL:</span> " + e;
    }
    envResult3 = (minAmount == null ? "<span class=\"fail\">FAIL</span>" : "<span class=\"pass\">avgAmount=" + avgAmount.toString() + "</span>");
    try {
        InitialContext ic = new InitialContext();
        envLookupResult3 = "java:comp/env/com.acme.test.AnnotationTest/avgAmount=" + ic.lookup("java:comp/env/com.acme.test.AnnotationTest/avgAmount");
    } catch (Exception e) {
        envLookupResult3 = "<span class=\"fail\">FAIL:</span> " + e;
    }
    try {
        InitialContext ic = new InitialContext();
        dsLookupResult = "java:comp/env/com.acme.test.AnnotationTest/myDatasource=" + ic.lookup("java:comp/env/com.acme.test.AnnotationTest/myDatasource");
    } catch (Exception e) {
        dsLookupResult = "<span class=\"fail\">FAIL:</span> " + e;
    }
    txResult = (myUserTransaction == null ? "<span class=\"fail\">FAIL</span>" : "<span class=\"pass\">myUserTransaction=" + myUserTransaction + "</span>");
    try {
        InitialContext ic = new InitialContext();
        txLookupResult = "java:comp/env/com.acme.test.AnnotationTest/myUserTransaction=" + ic.lookup("java:comp/env/com.acme.test.AnnotationTest/myUserTransaction");
    } catch (Exception e) {
        txLookupResult = "<span class=\"fail\">FAIL:</span> " + e;
    }
}
Also used : ServletException(javax.servlet.ServletException) IOException(java.io.IOException) InitialContext(javax.naming.InitialContext) PostConstruct(javax.annotation.PostConstruct)

Example 8 with PostConstruct

use of javax.annotation.PostConstruct in project facebook-recommender-demo by ManuelB.

the class FacebookRecommender method initRecommender.

/**
	 * This function will init the recommender
	 * it will load the CSV file from the resource folder,
	 * parse it and create the necessary data structures
	 * to create a recommender.
	 * The 
	 */
@PostConstruct
public void initRecommender() {
    try {
        // get the file which is part of the WAR as
        URL url = getClass().getClassLoader().getResource(DATA_FILE_NAME);
        // create a file out of the resource
        File data = new File(url.toURI());
        // create a map for saving the preferences (likes) for
        // a certain person
        Map<Long, List<Preference>> preferecesOfUsers = new HashMap<Long, List<Preference>>();
        // use a CSV parser for reading the file
        // use UTF-8 as character set
        CSVParser parser = new CSVParser(new InputStreamReader(new FileInputStream(data), "UTF-8"));
        // parse out the header
        // we are not using the header
        String[] header = parser.getLine();
        // should output person name
        log.fine(header[0] + " " + header[1]);
        String[] line;
        // go through every line
        while ((line = parser.getLine()) != null) {
            String person = line[0];
            String likeName = line[1];
            // other lines contained but not used
            // String category = line[2];
            // String id = line[3];
            // String created_time = line[4];
            // create a long from the person name
            long userLong = thing2long.toLongID(person);
            // store the mapping for the user
            thing2long.storeMapping(userLong, person);
            // create a long from the like name
            long itemLong = thing2long.toLongID(likeName);
            // store the mapping for the item
            thing2long.storeMapping(itemLong, likeName);
            List<Preference> userPrefList;
            // otherwise create a new one.
            if ((userPrefList = preferecesOfUsers.get(userLong)) == null) {
                userPrefList = new ArrayList<Preference>();
                preferecesOfUsers.put(userLong, userPrefList);
            }
            // add the like that we just found to this user
            userPrefList.add(new GenericPreference(userLong, itemLong, 1));
            log.fine("Adding " + person + "(" + userLong + ") to " + likeName + "(" + itemLong + ")");
        }
        // create the corresponding mahout data structure from the map
        FastByIDMap<PreferenceArray> preferecesOfUsersFastMap = new FastByIDMap<PreferenceArray>();
        for (Entry<Long, List<Preference>> entry : preferecesOfUsers.entrySet()) {
            preferecesOfUsersFastMap.put(entry.getKey(), new GenericUserPreferenceArray(entry.getValue()));
        }
        // create a data model 
        dataModel = new GenericDataModel(preferecesOfUsersFastMap);
        // Instantiate the recommender
        recommender = new GenericBooleanPrefItemBasedRecommender(dataModel, new LogLikelihoodSimilarity(dataModel));
    } catch (URISyntaxException e) {
        log.log(Level.SEVERE, "Problem with the file URL", e);
    } catch (FileNotFoundException e) {
        log.log(Level.SEVERE, DATA_FILE_NAME + " was not found", e);
    } catch (IOException e) {
        log.log(Level.SEVERE, "Error during reading line of file", e);
    }
}
Also used : HashMap(java.util.HashMap) GenericBooleanPrefItemBasedRecommender(org.apache.mahout.cf.taste.impl.recommender.GenericBooleanPrefItemBasedRecommender) FileNotFoundException(java.io.FileNotFoundException) URISyntaxException(java.net.URISyntaxException) URL(java.net.URL) GenericUserPreferenceArray(org.apache.mahout.cf.taste.impl.model.GenericUserPreferenceArray) GenericPreference(org.apache.mahout.cf.taste.impl.model.GenericPreference) ArrayList(java.util.ArrayList) List(java.util.List) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) FastByIDMap(org.apache.mahout.cf.taste.impl.common.FastByIDMap) PreferenceArray(org.apache.mahout.cf.taste.model.PreferenceArray) GenericUserPreferenceArray(org.apache.mahout.cf.taste.impl.model.GenericUserPreferenceArray) GenericDataModel(org.apache.mahout.cf.taste.impl.model.GenericDataModel) Preference(org.apache.mahout.cf.taste.model.Preference) GenericPreference(org.apache.mahout.cf.taste.impl.model.GenericPreference) LogLikelihoodSimilarity(org.apache.mahout.cf.taste.impl.similarity.LogLikelihoodSimilarity) CSVParser(org.apache.commons.csv.CSVParser) File(java.io.File) PostConstruct(javax.annotation.PostConstruct)

Example 9 with PostConstruct

use of javax.annotation.PostConstruct in project eureka by Netflix.

the class Route53Binder method start.

@Override
@PostConstruct
public void start() throws InterruptedException {
    doBind();
    timer.schedule(new TimerTask() {

        @Override
        public void run() {
            try {
                doBind();
            } catch (Throwable e) {
                logger.error("Could not bind to Route53", e);
            }
        }
    }, serverConfig.getRoute53BindingRetryIntervalMs(), serverConfig.getRoute53BindingRetryIntervalMs());
}
Also used : TimerTask(java.util.TimerTask) PostConstruct(javax.annotation.PostConstruct)

Example 10 with PostConstruct

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

the class PersonSessionBean method initDB.

@PostConstruct
private void initDB() {
    cluster = Cluster.builder().addContactPoint("localhost").build();
    Metadata metadata = cluster.getMetadata();
    System.out.printf("Connected to cluster: %s\n", metadata.getClusterName());
    for (Host host : metadata.getAllHosts()) {
        System.out.printf("Datacenter: %s; Host: %s; Rack: %s\n", host.getDatacenter(), host.getAddress(), host.getRack());
    }
    session = cluster.connect();
    session.execute("CREATE KEYSPACE IF NOT EXISTS test WITH replication " + "= {'class':'SimpleStrategy', 'replication_factor':1};");
    session.execute("CREATE TABLE IF NOT EXISTS test.person (" + "name text PRIMARY KEY," + "age int" + ");");
    selectAllPersons = session.prepare("SELECT * FROM test.person");
    insertPerson = session.prepare("INSERT INTO test.person (name, age) VALUES (?, ?);");
}
Also used : Metadata(com.datastax.driver.core.Metadata) Host(com.datastax.driver.core.Host) 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