當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。