Hi Jorg,
Sorry to open the thread again. But the issue is I'm getting OOM error
currently in tomcat and the webapplication is crushing. As u suggested I'm
calling the static TransportClient instance from contextInitialized() and
shutting down with contextDestroyed(). But the methods are not getting
called it seems. Trying like below.
Can you please check.
public class ESClientFactory implements ServletContextListener {
/** The logger. */
private static Logger logger = Logger.getLogger(ESClientFactory.class);
/** The instance. */
public static TransportClient instance;
/**
* Instantiates a new eS client factory.
*/
private ESClientFactory() {
}
/**
* Gets the single instance of ESClientFactory.
*
* @return single instance of ESClientFactory
*/
public static Client getInstance() {
String ipAddress = MessageTranslator.getMessage("es.cluster.ip");
int transportClientPort = 0;
String clusterName =
MessageTranslator.getMessage("es.cluster.name");
try {
transportClientPort =
Integer.parseInt(MessageTranslator
.getMessage("es.transportclient.port"));
}
catch (Exception e) {
transportClientPort = 9300;
LogImpl.setWarning(ESClientFactory.class, e);
}
logger.debug("got the client ip as :" + ipAddress + " and port :"
+ transportClientPort);
if (instance == null) {
logger
.debug("the client instance is null, creating a new
instance");
ImmutableSettings.Builder settings =
ImmutableSettings.settingsBuilder();
settings.put("cluster.name", clusterName);
settings.build();
instance =
new TransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(
ipAddress, transportClientPort));
logger.debug("returning the new created client instance...");
return instance;
}
logger
.debug("returning the existing transport client object
connection.");
return instance;
}
@Override
public void contextInitialized(ServletContextEvent sce) {
logger.debug("initializing the servletContextListener... TransportClient");
getInstance();
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
logger.debug("closing the servlet context");
shutdown();
logger.debug("successfully shutdown threadpool");
}
public synchronized void shutdown() {
if (instance != null) {
logger.debug("shutdown started");
instance.close();
instance.threadPool().shutdown();
instance = null;
logger.debug("shutdown complete");
}
}
}
--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/814fdb41-461b-4b5c-8bad-835039d76c24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.