SystemConfigProducer implements Extension { Bean<FileSystem> createFileSystemBean(final BeanManager bm, final InjectionTarget<DummyFileSystem> it, final Space space, String ioService, String beanName, String fsName) { return new Bean<FileSystem>() { @Override public Class<?> getBeanClass() { return FileSystem.class; } @Override public Set<InjectionPoint> getInjectionPoints() { return it.getInjectionPoints(); } @Override public String getName() { return beanName; } @Override public Set<Annotation> getQualifiers() { return new HashSet<Annotation>() {{ add(new AnnotationLiteral<Default>() { }); add(new AnnotationLiteral<Any>() { }); add(new NamedLiteral(beanName)); }}; } @Override public Class<? extends Annotation> getScope() { return ApplicationScoped.class; } @Override public Set<Class<? extends Annotation>> getStereotypes() { return Collections.emptySet(); } @Override public Set<Type> getTypes() { return new HashSet<Type>() {{ add(FileSystem.class); add(LockableFileSystem.class); add(Object.class); }}; } @Override public boolean isAlternative() { return false; } @Override public boolean isNullable() { return false; } @Override public FileSystem create(CreationalContext<FileSystem> ctx) { final SpacesAPI spaces = getSpaces(bm); final Bean<IOService> bean = (Bean<IOService>) bm.getBeans(ioService).iterator().next(); final CreationalContext<IOService> _ctx = bm.createCreationalContext(bean); final IOService ioService = (IOService) bm.getReference(bean, IOService.class, _ctx); FileSystem fs; URI uri = resolveFSURI(spaces, space, fsName); try { fs = ioService.newFileSystem( uri, new HashMap<String, Object>() {{ put("init", Boolean.TRUE); put("internal", Boolean.TRUE); }}); } catch (FileSystemAlreadyExistsException e) { fs = ioService.getFileSystem(uri); } PriorityDisposableRegistry.register(beanName, fs); return fs; } @Override public void destroy(final FileSystem instance, final CreationalContext<FileSystem> ctx) { try { instance.dispose(); PriorityDisposableRegistry.unregister(beanName); } catch (final Exception ex) { logger.warn(ex.getMessage(), ex); } ctx.release(); } }; }  void processSystemFSProducer(@Observes ProcessProducer<?, FileSystem> pp); void processPluginsFSProducer(@Observes ProcessProducer<?, FileSystem> pp); void processPerspectivesFSProducer(@Observes ProcessProducer<?, FileSystem> pp); void processDatasetsFSProducer(@Observes ProcessProducer<?, FileSystem> pp); void processNavigationFSProducer(@Observes ProcessProducer<?, FileSystem> pp); void processIOServiceProducer(@Observes ProcessProducer<?, IOService> pp); void processBean(@Observes final ProcessBean<X> event); void afterDeploymentValidation(final @Observes AfterDeploymentValidation event,
                                          final BeanManager manager);  }
@Test public void createAndDestroyFSShouldRegisterUnregisterOnPriorityDisposableRegistry() { when(bm.getBeans("configIO")).thenReturn(configIOBeans); when(bm.getReference(eq(ioServiceBean), eq(IOService.class), any(CreationalContext.class))) .thenReturn(ioServiceMock); when(ioServiceMock.newFileSystem(any(URI.class), any(Map.class))) .thenReturn(fs); final Bean fileSystemBean = producer.createFileSystemBean(bm, mock(InjectionTarget.class), mock(Space.class), "configIO", "systemFS", SystemConfigProducer.SYSTEM); assertNull(PriorityDisposableRegistry.get("systemFS")); fileSystemBean.create(mock(CreationalContext.class)); assertNotNull(PriorityDisposableRegistry.get("systemFS")); fileSystemBean.destroy(fs, mock(CreationalContext.class)); assertNull(PriorityDisposableRegistry.get("systemFS")); }