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);
}
}
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();
}
}
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();
}
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);
}
}
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());
}
});
}
Aggregations