当前位置: 首页>>代码示例>>Java>>正文


Java Observes类代码示例

本文整理汇总了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())));
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:17,代码来源:GitHubStepObserver.java

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

    }

}
 
开发者ID:abhirockzz,项目名称:redis-websocket-javaee,代码行数:23,代码来源:MeetupGroupsLiveLeaderboardEndpoint.java

示例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)));
    }

}
 
开发者ID:wildfly-extras,项目名称:wildfly-microprofile-config,代码行数:27,代码来源:ConfigExtension.java

示例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);
        }
    }

}
 
开发者ID:RETIT,项目名称:continuous-performance-evaluation,代码行数:26,代码来源:RealtimeCargoTrackingService.java

示例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");
    }
 
开发者ID:abhirockzz,项目名称:accs-javaee8,代码行数:21,代码来源:TickTockTickTock.java

示例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());
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:17,代码来源:AuditLogServiceBeanIT.java

示例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;
    }
  }
}
 
开发者ID:microbean,项目名称:microbean-kubernetes-client-cdi,代码行数:20,代码来源:KubernetesClientExtension.java

示例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)));
}
 
开发者ID:wildfly-extras,项目名称:wildfly-microprofile-config,代码行数:24,代码来源:ConfigExtension.java

示例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());
            }
        }
    }
}
 
开发者ID:wwu-pi,项目名称:tap17-muggl-javaee,代码行数:18,代码来源:StatusEndpoint.java

示例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);
    }
}
 
开发者ID:PaperCutSoftware,项目名称:dust-api,代码行数:13,代码来源:DeviceSlackResource.java

示例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);
    }
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:19,代码来源:MissionControlStatusEndpoint.java

示例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());
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:10,代码来源:AnalyticsProviderBase.java

示例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())));
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:16,代码来源:OpenShiftStepObserver.java

示例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));
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:38,代码来源:OpenShiftStepObserver.java

示例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));
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:33,代码来源:GitHubStepObserver.java


注:本文中的javax.enterprise.event.Observes类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。