LoggerProducer.java is a class used to produce Loggers to be injected in CDI beans with:
@Inject
Logger LOG;
Full code:
import javax.ejb.Singleton;
/**
* @author rveldpau
*/
@Singleton
public class LoggerProducer {
private Map<String, Logger> loggers = new HashMap<>();
@Produces
public Logger getProducer(InjectionPoint ip) {
String key = getKeyFromIp(ip);
if (!loggers.containsKey(key)) {
loggers.put(key, Logger.getLogger(key));
}
return loggers.get(key);
}
private String getKeyFromIp(InjectionPoint ip) {
return ip.getMember().getDeclaringClass().getCanonicalName();
}
}
QUESTION: can @Singleton
be safely turned into @ApplicationScoped
?
I mean, why would anyone want an EJB here ? Are there technical reasons, since no transactions are involved, and (AFAIK) it would be thread-safe anyway ?
I'm obviously referring to javax.enterprise.context.ApplicationScoped
, not to javax.faces.bean.ApplicationScoped
.
@ApplicationScoped
is, thanks for the comment BTW – Viridescentjavax.ejb.Singleton
orjavax.inject.Singleton
? – Unsung