本文整理汇总了Java中javax.enterprise.event.Observes类的典型用法代码示例。如果您正苦于以下问题:Java Observes类的具体用法?Java Observes怎么用?Java Observes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Observes类属于javax.enterprise.event包,在下文中一共展示了Observes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createGitHubRepository
import javax.enterprise.event.Observes; //导入依赖的package包/类
public void createGitHubRepository(@Observes @Step(GITHUB_CREATE) CreateProjectileEvent event) {
assert event.getGitHubRepository() == null : "Github repository is already set";
CreateProjectile projectile = event.getProjectile();
String repositoryDescription = projectile.getGitHubRepositoryDescription();
String repositoryName = projectile.getGitHubRepositoryName();
if (repositoryName == null) {
repositoryName = projectile.getOpenShiftProjectName();
}
GitHubService gitHubService = gitHubServiceFactory.create(projectile.getGitHubIdentity());
GitRepository gitHubRepository = gitHubService.createRepository(repositoryName, repositoryDescription);
event.setGitHubRepository(gitHubRepository);
statusEvent.fire(new StatusMessageEvent(projectile.getId(), GITHUB_CREATE,
singletonMap("location", gitHubRepository.getHomepage())));
}
示例2: broadcast
import javax.enterprise.event.Observes; //导入依赖的package包/类
public void broadcast(@Observes @LeaderDataQualifier String leaderboard) {
for (final Session s : CLIENTS) {
if (s != null && s.isOpen()) {
/**
* Asynchronous push
*/
s.getAsyncRemote().sendText(leaderboard, new SendHandler() {
@Override
public void onResult(SendResult result) {
if (result.isOK()) {
//Logger.getLogger(MeetupGroupsLiveLeaderboardEndpoint.class.getName()).log(Level.INFO, " sent to client {0}", s.getId());
} else {
Logger.getLogger(MeetupGroupsLiveLeaderboardEndpoint.class.getName()).log(Level.SEVERE, "Could not send to client " + s.getId(),
result.getException());
}
}
});
}
}
}
示例3: validate
import javax.enterprise.event.Observes; //导入依赖的package包/类
public void validate(@Observes AfterDeploymentValidation add, BeanManager bm) {
List<String> deploymentProblems = new ArrayList<>();
Config config = ConfigProvider.getConfig();
for (InjectionPoint injectionPoint : injectionPoints) {
Type type = injectionPoint.getType();
ConfigProperty configProperty = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class);
if (type instanceof Class) {
String key = getConfigKey(injectionPoint, configProperty);
if (!config.getOptionalValue(key, (Class)type).isPresent()) {
String defaultValue = configProperty.defaultValue();
if (defaultValue == null ||
defaultValue.equals(ConfigProperty.UNCONFIGURED_VALUE)) {
deploymentProblems.add("No Config Value exists for " + key);
}
}
}
}
if (!deploymentProblems.isEmpty()) {
add.addDeploymentProblem(new DeploymentException("Error while validating Configuration\n"
+ String.join("\n", deploymentProblems)));
}
}
示例4: onCargoInspected
import javax.enterprise.event.Observes; //导入依赖的package包/类
public void onCargoInspected(@Observes @CargoInspected Cargo cargo) {
Writer writer = new StringWriter();
try (JsonGenerator generator = Json.createGenerator(writer)) {
generator
.writeStartObject()
.write("trackingId", cargo.getTrackingId().getIdString())
.write("origin", cargo.getOrigin().getName())
.write("destination", cargo.getRouteSpecification().getDestination().getName())
.write("lastKnownLocation", cargo.getDelivery().getLastKnownLocation().getName())
.write("transportStatus", cargo.getDelivery().getTransportStatus().toString())
.writeEnd();
}
String jsonValue = writer.toString();
for (Session session : sessions) {
try {
session.getBasicRemote().sendText(jsonValue);
} catch (IOException ex) {
logger.log(Level.WARNING, "Unable to publish WebSocket message", ex);
}
}
}
示例5: onTrigger
import javax.enterprise.event.Observes; //导入依赖的package包/类
public void onTrigger(@Observes @Initialized(ApplicationScoped.class) Object test) {
mes.submit(new Runnable() {
@Override
public void run() {
try {
while (true) {
eventBus.fireAsync(new TickTock("tick-" + gen.nextInt(10), "tock-" + gen.nextInt(10)));
System.out.println("Fired CDI event from thread " + Thread.currentThread().getName());
Thread.sleep(5000);
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
System.out.println("Scheduler initialized");
}
示例6: saveAuditLogEntries_hasObserverMethodAfterSuccessAnnotation
import javax.enterprise.event.Observes; //导入依赖的package包/类
@Test
public void saveAuditLogEntries_hasObserverMethodAfterSuccessAnnotation() {
// given
AuditLogEntries auditLogEntries = new AuditLogEntries(
new ArrayList<AuditLogEntry>());
List<ObserverMethod> observerMethods = contextManager
.findObserverMethods(auditLogEntries);
Method method = observerMethods.get(0).getMethod();
// when
Observes observes = (Observes) contextManager.searchAnnotation(method,
Observes.class);
// then
assertEquals(TransactionPhase.AFTER_SUCCESS, observes.during());
}
示例7: stopWatching
import javax.enterprise.event.Observes; //导入依赖的package包/类
private final void stopWatching(@Observes @BeforeDestroyed(ApplicationScoped.class) @Priority(LIBRARY_BEFORE) final Object event) throws Exception {
final Closeable watch = this.watch;
if (watch != null) {
KubernetesClientException closeException = this.closeException;
try {
watch.close();
} catch (final Exception everything) {
if (closeException != null) {
closeException.addSuppressed(everything);
throw closeException;
} else {
throw everything;
}
}
if (closeException != null) {
throw closeException;
}
}
}
示例8: registerConfigProducer
import javax.enterprise.event.Observes; //导入依赖的package包/类
public void registerConfigProducer(@Observes AfterBeanDiscovery abd, BeanManager bm) {
// excludes type that are already produced by ConfigProducer
Set<Class> types = injectionPoints.stream()
.filter(ip -> ip.getType() instanceof Class
&& ip.getType() != String.class
&& ip.getType() != Boolean.class
&& ip.getType() != Boolean.TYPE
&& ip.getType() != Integer.class
&& ip.getType() != Integer.TYPE
&& ip.getType() != Long.class
&& ip.getType() != Long.TYPE
&& ip.getType() != Float.class
&& ip.getType() != Float.TYPE
&& ip.getType() != Double.class
&& ip.getType() != Double.TYPE
&& ip.getType() != Duration.class
&& ip.getType() != LocalDate.class
&& ip.getType() != LocalTime.class
&& ip.getType() != LocalDateTime.class)
.map(ip -> (Class) ip.getType())
.collect(Collectors.toSet());
types.forEach(type -> abd.addBean(new ConfigInjectionBean(bm, type)));
}
示例9: updateStatus
import javax.enterprise.event.Observes; //导入依赖的package包/类
public static synchronized void updateStatus(@Observes StatusEvent event) {
log.info("updateStatus");
for (Session s : sessions) {
if (s.isOpen()) {
try {
String studentUpdate = jsonStudentUpdate(event.getStudent());
s.getBasicRemote().sendText(studentUpdate);
log.log(Level.INFO, "[StatusEndpoint] {0} is now {1}",
new Object[]{event.getStudent().getName(),
event.getStudent().getStatus()});
/* Send update */
} catch (IOException e) {
log.log(Level.INFO, "[StatusEndpoint] {0}", e.getMessage());
}
}
}
}
示例10: handleDeviceEvent
import javax.enterprise.event.Observes; //导入依赖的package包/类
public void handleDeviceEvent(@Observes final DeviceEvent event) {
switch (event.type) {
case CLAIMED:
sendNotifications(event.claim, true);
break;
case UNCLAIMED:
sendNotifications(event.claim, false);
break;
default:
throw new IllegalArgumentException("Unknown event: " + event.type);
}
}
示例11: onEvent
import javax.enterprise.event.Observes; //导入依赖的package包/类
/**
* Listen to status changes and pushes them to the registered sessions
*
* @param msg the status message to be send
* @throws IOException when message could not be serialized to JSON
*/
public void onEvent(@Observes StatusMessageEvent msg) throws IOException {
UUID msgId = msg.getId();
Session session = peers.get(msgId);
String message = objectMapper.writeValueAsString(msg);
if (session != null) {
session.getAsyncRemote().sendText(message);
} else {
List<String> messages = messageBuffer.computeIfAbsent(msgId, k -> new ArrayList<>());
messages.add(message);
log.log(Level.WARNING, "No active WebSocket session was found for projectile {0}", msgId);
}
}
示例12: onEvent
import javax.enterprise.event.Observes; //导入依赖的package包/类
public void onEvent(@Observes LaunchEvent launch) throws IOException {
runPostTrackingMessage(
launch.getUser(),
launch.getId(),
launch.getGithubRepo(),
launch.getOpenshiftProjectName(),
launch.getMission(),
launch.getRuntime());
}
示例13: createOpenShiftProject
import javax.enterprise.event.Observes; //导入依赖的package包/类
/**
* Creates an Openshift project if the project doesn't exist.
*/
public void createOpenShiftProject(@Observes @Step(OPENSHIFT_CREATE) CreateProjectileEvent event) {
assert event.getOpenShiftProject() == null : "OpenShift project is already set";
CreateProjectile projectile = event.getProjectile();
Optional<OpenShiftCluster> cluster = openShiftClusterRegistry.findClusterById(projectile.getOpenShiftClusterName());
OpenShiftService openShiftService = openShiftServiceFactory.create(cluster.get(), projectile.getOpenShiftIdentity());
String projectName = projectile.getOpenShiftProjectName();
OpenShiftProject openShiftProject = openShiftService.findProject(projectName).orElseGet(() -> openShiftService.createProject(projectName));
event.setOpenShiftProject(openShiftProject);
statusEvent.fire(new StatusMessageEvent(projectile.getId(), OPENSHIFT_CREATE,
singletonMap("location", openShiftProject.getConsoleOverviewUrl())));
}
示例14: configureBuildPipeline
import javax.enterprise.event.Observes; //导入依赖的package包/类
public void configureBuildPipeline(@Observes @Step(OPENSHIFT_PIPELINE) CreateProjectileEvent event) {
assert event.getGitHubRepository() != null : "Github repository is not set";
assert event.getOpenShiftProject() != null : "OpenShift project is not set";
CreateProjectile projectile = event.getProjectile();
Optional<OpenShiftCluster> cluster = openShiftClusterRegistry.findClusterById(projectile.getOpenShiftClusterName());
OpenShiftService openShiftService = openShiftServiceFactory.create(cluster.get(), projectile.getOpenShiftIdentity());
OpenShiftProject openShiftProject = event.getOpenShiftProject();
GitRepository gitHubRepository = event.getGitHubRepository();
File path = projectile.getProjectLocation().toFile();
List<AppInfo> apps = findProjectApps(path);
if (apps.isEmpty()) {
// Use Jenkins pipeline build
openShiftService.configureProject(openShiftProject, gitHubRepository.getGitCloneUri());
} else {
// Use S2I builder templates
for (AppInfo app : apps) {
for (File tpl : app.resources) {
applyTemplate(openShiftService, gitHubRepository, openShiftProject, app, tpl);
}
}
for (AppInfo app : apps) {
for (File tpl : app.services) {
applyTemplate(openShiftService, gitHubRepository, openShiftProject, app, tpl);
}
}
for (AppInfo app : apps) {
for (File tpl : app.apps) {
applyTemplate(openShiftService, gitHubRepository, openShiftProject, app, tpl);
}
}
}
statusEvent.fire(new StatusMessageEvent(projectile.getId(), OPENSHIFT_PIPELINE));
}
示例15: createWebHooks
import javax.enterprise.event.Observes; //导入依赖的package包/类
/**
* Creates a webhook on the github repo to fire a build / deploy when changes happen on the project.
*/
public void createWebHooks(@Observes @Step(GITHUB_WEBHOOK) CreateProjectileEvent event) {
assert event.getGitHubRepository() != null : "Github repository is not set";
CreateProjectile projectile = event.getProjectile();
Optional<OpenShiftCluster> cluster = openShiftClusterRegistry.findClusterById(projectile.getOpenShiftClusterName());
OpenShiftService openShiftService = openShiftServiceFactory.create(cluster.get(), projectile.getOpenShiftIdentity());
OpenShiftProject openShiftProject = openShiftService.findProject(projectile.getOpenShiftProjectName()).get();
GitHubService gitHubService = gitHubServiceFactory.create(projectile.getGitHubIdentity());
GitRepository gitHubRepository = event.getGitHubRepository();
List<GitHook> webhooks = new ArrayList<>();
for (URL webhookUrl : openShiftService.getWebhookUrls(openShiftProject)) {
GitHook gitHubWebhook;
try {
gitHubWebhook = gitHubService.createHook(gitHubRepository, webhookUrl,
GitHubWebhookEvent.PUSH.name(),
GitHubWebhookEvent.PULL_REQUEST.name(),
GitHubWebhookEvent.ISSUE_COMMENT.name());
} catch (final DuplicateHookException dpe) {
// Swallow, it's OK, we've already forked this repo
log.log(Level.FINE, dpe.getMessage(), dpe);
gitHubWebhook = ((GitHubServiceSpi) gitHubService).getWebhook(gitHubRepository, webhookUrl);
}
webhooks.add(gitHubWebhook);
}
event.setWebhooks(webhooks);
statusEvent.fire(new StatusMessageEvent(projectile.getId(), GITHUB_WEBHOOK));
}