下面列出了怎么用javax.enterprise.inject.Disposes的API类实例代码及写法,或者点击链接到github查看源代码。
public void closeInputStream(@Disposes
@InjectableResource(resourceProvider = InjectableResourceProvider.class, location = "")
InputStream inputStream)
{
if (inputStream != null)
{
try
{
inputStream.close();
}
catch (IOException e)
{
if (logger.isLoggable(Level.FINE))
{
logger.log(Level.FINE,"Unable to close input stream ",e);
}
}
}
}
private static void validateDisposeMethods(final CdiEjbBean<?> bean) {
if (!bean.getBeanContext().isLocalbean()) {
for (final Method m : bean.getBeanContext().getBeanClass().getMethods()) {
if (m.getDeclaringClass().equals(Object.class)) {
continue;
}
if (m.getParameterTypes().length > 0) {
for (final Annotation[] a : m.getParameterAnnotations()) {
for (final Annotation ann : a) {
final Method method = doResolveViewMethod(bean, m);
if (ann.annotationType().equals(Disposes.class) &&
(method == null || bean.getBeanContext().getBusinessRemoteInterfaces().contains(method.getDeclaringClass()))) {
throw new WebBeansConfigurationException("@Disposes is forbidden on non business or remote EJB methods");
}
}
}
}
}
}
}
protected void closeSecondEntityManager(@Disposes @Second EntityManager entityManager)
{
if (entityManager.isOpen())
{
entityManager.close();
}
closeEntityManagerCountSecondEntityManager++;
}
protected void closeEntityManager(@Disposes EntityManager entityManager)
{
if (entityManager.isOpen())
{
entityManager.close();
}
closeEntityManagerCount++;
}
void dipose(@Disposes Long value, @MyQualifier String injectedString, Instance<Pong> pongs) {
assertNotNull(injectedString);
DISPOSED.set(value);
pongs.forEach(p -> {
assertEquals("OK", p.id);
});
}
void destroyJsonb(@Disposes final Jsonb jsonb) {
try {
jsonb.close();
} catch (final Exception e) {
log.error(e.getMessage(), e);
}
}
public void close(@Disposes final Jsonb jsonb) {
try {
jsonb.close();
} catch (final Exception e) {
log.warn(e.getMessage(), e);
}
}
public void dispose(@Disposes @Default EntityManager entityManager)
{
if (entityManager.isOpen())
{
entityManager.close();
}
}
protected void closeSecondEntityManager(@Disposes @Second EntityManager entityManager)
{
if (entityManager.isOpen())
{
entityManager.close();
}
closeEntityManagerCountSecondEntityManager++;
}
public void dispose(@Disposes @Default EntityManager entityManager)
{
if (entityManager.isOpen())
{
entityManager.close();
}
}
public void closeLogHandler(@Disposes LogHandler handler) {
switch (type) {
case 1:
System.out.println("Closing File handler!");
break;
case 2:
System.out.println("Closing DB handler!");
break;
case 3:
default:
System.out.println("Closing Console handler!");
}
}
protected void closeFirstEntityManager(@Disposes @First EntityManager entityManager)
{
if (entityManager.isOpen())
{
entityManager.close();
}
closeEntityManagerCountFirstEntityManager++;
}
public void close(@Disposes final Jsonb jsonb) {
try {
jsonb.close();
} catch (final Exception e) {
log.log(Level.WARNING, e.getMessage(), e);
}
}
protected void closeFirstEntityManager(@Disposes @First EntityManager entityManager)
{
if (entityManager.isOpen())
{
entityManager.close();
}
closeEntityManagerCountFirstEntityManager++;
}
protected void closeEntityManager(@Disposes EntityManager entityManager)
{
if (entityManager.isOpen())
{
entityManager.close();
}
closeEntityManagerCount++;
}
protected void closeEntityManager(@Disposes @First EntityManager entityManager)
{
if (entityManager.isOpen())
{
entityManager.close();
}
closeEntityManagerCount++;
}
protected void closeEntityManager(@Disposes EntityManager entityManager)
{
if (entityManager.isOpen())
{
entityManager.close();
}
closeEntityManagerCount++;
}
protected void closeDefaultEntityManager(@Disposes @Default EntityManager entityManager)
{
if (entityManager.isOpen())
{
entityManager.close();
}
closeEntityManagerCountDefaultEntityManager++;
}
protected void closeFirstEntityManager(@Disposes @First EntityManager entityManager)
{
if (entityManager.isOpen())
{
entityManager.close();
}
closeEntityManagerCountFirstEntityManager++;
}
protected void closeSecondEntityManager(@Disposes @Second EntityManager entityManager)
{
if (entityManager.isOpen())
{
entityManager.close();
}
closeEntityManagerCountSecondEntityManager++;
}
protected void closeDefaultEntityManager(@Disposes @Default EntityManager entityManager)
{
if (entityManager.isOpen())
{
entityManager.close();
}
closeEntityManagerCountDefaultEntityManager++;
}
public void stopStorageProducer(@Disposes ProducerActions<String, Str.StorageValue> producer) throws Exception {
producer.close();
}
public void stopLivenessCheck(@Disposes CloseableSupplier<Boolean> check) throws Exception {
check.close();
}
public void stopSnapshotProducer(@Disposes ProducerActions<Long, StorageSnapshot> producer) throws Exception {
producer.close();
}
public void stopStorageProducer(@Disposes ProducerActions<Cmmn.UUID, Str.StorageValue> producer) throws Exception {
producer.close();
}
public void close(@Disposes MongoClient toClose) {
toClose.close();
}
public void shutdown(@Disposes @MPConfigBean.Max5Queue ManagedExecutor executor) {
executor.shutdown();
}
public void close(@Disposes EntityManager em) {
System.out.println("closing entity manager");
em.close();
}
void dispose(@Disposes @ViewEngineConfig JadeConfiguration jade) {
jade.clearCache();
}
public void disposeExecutor(@Disposes ManagedExecutor me) {
me.shutdown();
}