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


Java CDI.current方法代码示例

本文整理汇总了Java中javax.enterprise.inject.spi.CDI.current方法的典型用法代码示例。如果您正苦于以下问题:Java CDI.current方法的具体用法?Java CDI.current怎么用?Java CDI.current使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.enterprise.inject.spi.CDI的用法示例。


在下文中一共展示了CDI.current方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: filter

import javax.enterprise.inject.spi.CDI; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
    Instance<Object> instance = CDI.current();
    User user = instance.select(User.class).get();

    List<AccountRole> roles = user.getAccountRoles();
    if (Arrays.stream(permissions.roles()).anyMatch(roles::contains)) {
        return;
    }

    Permission permission = instance.select(permissions.value()).get();
    if (permission.test(requestContext)) {
        return;
    }

    throw new ForbiddenException();
}
 
开发者ID:backpaper0,项目名称:sealion,代码行数:18,代码来源:PermissionProvider.java

示例2: run

import javax.enterprise.inject.spi.CDI; //导入方法依赖的package包/类
public void run() {
  CDI<Object> cdi = CDI.current();

  // Start console listener
  ConsoleApi consoleApi = cdi.select(ConsoleApi.class).get();
  consoleApi.init();

  // Run system boot
  SystemBoot systemBoot = cdi.select(SystemBoot.class).get();
  systemBoot.runSetupTasks();
  cdi.destroy(systemBoot);

  // Init ComponentManager
  cdi.select(ComponentManager.class).get();

  // Start IrcSession
  cdi.select(IrcSession.class).get().start();
  cdi.select(TwitchWebhookSession.class).get().start();

  // Start REST API
  cdi.select(RestServerController.class).get().start();

  // Start listening for console commands
  consoleApi.initCliCommands();

  // The EventBusSubscriberInterceptor will register subscribers
  // Events are emitted by the IRC clients to bootstrap components and services
}
 
开发者ID:Juraji,项目名称:Biliomi,代码行数:29,代码来源:Biliomi.java

示例3: get

import javax.enterprise.inject.spi.CDI; //导入方法依赖的package包/类
@Override
public Publisher<T> get(Object event) {
    CDI<Object> cdi = CDI.current();
    List<InstanceHolder> instanceHolders = new ArrayList<>();
    List<Object> parameters = new ArrayList<>();
    for(AnnotatedParameter<?> ap : annotatedMethod.getParameters()) {
        if(ap.isAnnotationPresent(ObservesReactor.class)) {
            parameters.add(event);
        } else {
            InstanceHolder holder = getReference(cdi, ap.getJavaParameter().getType(), ap.getAnnotations());
            instanceHolders.add(holder);
            parameters.add(holder.instance);
        }
    }
    InstanceHolder eventReceiver = getReference(cdi,annotatedType.getJavaClass(),
            findQualifiers(annotatedType.getAnnotations()));
    Object[] params = parameters.toArray();
    try {
        Object result = targetMethod.invoke(eventReceiver.instance, params);
        if(returnsPublisher) {
            return (Publisher<T>) result;
        } else {
            return Mono.just((T)result).doAfterTerminate(() -> instanceHolders.forEach(InstanceHolder::destroy));
        }
    } catch (IllegalAccessException | InvocationTargetException e) {
        return Mono.fromSupplier(() -> { throw new RuntimeException(e); });
    } finally {
        eventReceiver.destroy();
    }
}
 
开发者ID:johnament,项目名称:reactive-cdi-events,代码行数:31,代码来源:ReactorObserverRegistry.java

示例4: testEmitEvents

import javax.enterprise.inject.spi.CDI; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testEmitEvents(@Mocked ManagedScheduledExecutorService executor, 
        @Mocked KafkaConsumer<String,String> consumer,
        @Mocked ScheduledFuture future, @Mocked ConsumerRecord<String,String> record1, @Mocked ConsumerRecord<String,String> record2){
    
    KafkaCDIBridge kcdib = new KafkaCDIBridge();
    
    Deencapsulation.setField(kcdib,"consumer",consumer);
    Deencapsulation.setField(kcdib,"executor",executor);
    
    Map<TopicPartition, List<ConsumerRecord<String,String>>> data = new HashMap<>();
    List<ConsumerRecord<String,String>> records = new ArrayList<>();
    records.add(record1);
    records.add(record2);
    data.put(new TopicPartition("playerEvents", 1), records);
    ConsumerRecords<String, String> cr = new ConsumerRecords<String,String>(data);
    
    new Expectations() {{
       executor.scheduleWithFixedDelay((Runnable) any,anyLong,anyLong,(TimeUnit)any); result = future;
       consumer.subscribe((List<String>)any);
       record1.offset(); result=0L;
       record2.offset(); result=1L;
       record1.key(); result="stilettos";
       record2.key(); result="wedge";
       record1.topic(); result="playerEvents";
       record2.topic(); result="playerEvents";
       record1.value(); result="leather";
       record2.value(); result="patent";
    }};
    
    kcdib.init(null);
    
    new Verifications() {{
        //retrieve and invoke the nested thread..
        Runnable r;
        executor.scheduleWithFixedDelay(r = withCapture(), anyLong, anyLong, (TimeUnit)any);
        consumer.subscribe((List<String>)any);
        
        new Expectations() {{
            CDI.current(); result = cdi;
            cdi.getBeanManager(); result = bm;
            consumer.poll(anyLong); result = cr;
        }};
        
        r.run();
        
        new Verifications() {{
            List<Object> events = new ArrayList<>();
            
            //verify that 2 fire event calls are made.
            
            bm.fireEvent(withCapture(events)); times = 2;
            
            Assert.assertEquals(2, events.size());
            Assert.assertEquals(GameOnEvent.class, events.get(0).getClass());
            Assert.assertEquals(GameOnEvent.class, events.get(1).getClass());
            GameOnEvent e1 = (GameOnEvent)events.get(0);
            GameOnEvent e2 = (GameOnEvent)events.get(1);
            
            Assert.assertEquals("stilettos",e1.getKey());
            Assert.assertEquals("wedge",e2.getKey());
            Assert.assertEquals("playerEvents",e1.getTopic());
            Assert.assertEquals("playerEvents",e2.getTopic());
            Assert.assertEquals("leather",e1.getValue());
            Assert.assertEquals("patent",e2.getValue());
            Assert.assertEquals(0L,e1.getOffset());
            Assert.assertEquals(1L,e2.getOffset());
        }};
        
        
    }};
    
    new Expectations() {{
        future.cancel(anyBoolean);
        consumer.close();
    }};
    
    kcdib.destroy(null);
    
}
 
开发者ID:gameontext,项目名称:gameon-mediator,代码行数:82,代码来源:CDIBridgeTest.java


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