use of org.jivesoftware.openfire.container.PluginManager in project Openfire by igniterealtime.
the class ClusterClassLoader method getResources.
public Enumeration<URL> getResources(String name) throws IOException {
Enumeration<URL> answer = null;
try {
answer = hazelcastClassloader.getResources(name);
} catch (IOException e) {
// Ignore
}
if (answer == null || !answer.hasMoreElements()) {
PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
for (Plugin plugin : pluginManager.getPlugins()) {
String pluginName = pluginManager.getPluginDirectory(plugin).getName();
if ("hazelcast".equals(pluginName) || "admin".equals(pluginName)) {
continue;
}
PluginClassLoader pluginClassloader = pluginManager.getPluginClassloader(plugin);
try {
answer = pluginClassloader.getResources(name);
} catch (IOException e) {
// Ignore
}
if (answer != null && answer.hasMoreElements()) {
return answer;
}
}
}
return answer;
}
use of org.jivesoftware.openfire.container.PluginManager in project Openfire by igniterealtime.
the class SchemaManager method checkPluginSchema.
/**
* Checks the plugin's database schema (if one is required) to ensure that it's
* installed and up to date. If the schema isn't present or up to date, an automatic
* update will be attempted.
*
* @param plugin the plugin.
* @return true if database schema checked out fine, or was automatically installed
* or updated successfully, or if it isn't needed. False will only be returned
* if there is an error.
*/
public boolean checkPluginSchema(final Plugin plugin) {
final PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
String schemaKey = pluginManager.getDatabaseKey(plugin);
int schemaVersion = pluginManager.getDatabaseVersion(plugin);
// need database tables.
if (schemaKey == null || schemaVersion == -1) {
return true;
}
Connection con = null;
try {
con = DbConnectionManager.getConnection();
return checkSchema(con, schemaKey, schemaVersion, new ResourceLoader() {
@Override
public InputStream loadResource(String resourceName) {
File file = new File(pluginManager.getPluginDirectory(plugin) + File.separator + "database", resourceName);
try {
return new FileInputStream(file);
} catch (FileNotFoundException e) {
return null;
}
}
});
} catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("upgrade.database.failure"), e);
System.out.println(LocaleUtils.getLocalizedString("upgrade.database.failure"));
} finally {
DbConnectionManager.closeConnection(con);
}
return false;
}
use of org.jivesoftware.openfire.container.PluginManager in project Openfire by igniterealtime.
the class ConnectionManagerImpl method startListeners.
/**
* Starts all listeners. This ensures that all those that are enabled will start accept connections.
*/
private synchronized void startListeners() {
// Check if plugins have been loaded
Log.debug("Received a request to start listeners. Have plugins been loaded?");
PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
if (!pluginManager.isExecuted()) {
Log.debug("Plugins not yet loaded. Waiting for plugins to be loaded...");
pluginManager.addPluginManagerListener(new PluginManagerListener() {
public void pluginsMonitored() {
Log.debug("Received plugin monitor event! Plugins should now be loaded.");
// Stop listening for plugin events
XMPPServer.getInstance().getPluginManager().removePluginManagerListener(this);
// Start listeners
startListeners();
}
});
return;
}
Log.debug("Starting listeners...");
for (final ConnectionListener listener : getListeners()) {
try {
listener.start();
Log.debug("Started '{}' (port {}) listener.", listener.getType(), listener.getPort());
} catch (RuntimeException ex) {
Log.error("An exception occurred while starting listener " + listener, ex);
}
}
// Start the HTTP client listener.
try {
HttpBindManager.getInstance().start();
Log.debug("Started HTTP client listener.");
} catch (RuntimeException ex) {
Log.error("An exception occurred while starting HTTP Bind listener ", ex);
}
}
use of org.jivesoftware.openfire.container.PluginManager in project Openfire by igniterealtime.
the class LocaleUtils method getLocalizedString.
/**
* Returns an internationalized string loaded from a resource bundle from
* the passed in plugin, using the passed in Locale.
*
* If the plugin name is <tt>null</tt>, the key will be looked up using the
* standard resource bundle.
*
* If the locale is <tt>null</tt>, the Jive Global locale will be used.
*
* @param key
* the key to use for retrieving the string from the appropriate
* resource bundle.
* @param pluginName
* the name of the plugin to load the require resource bundle
* from.
* @param arguments
* a list of objects to use which are formatted, then inserted
* into the pattern at the appropriate places.
* @param locale
* the locale to use for retrieving the appropriate
* locale-specific string.
* @param fallback
* if <tt>true</tt>, the global locale used by Openfire will be
* used if the requested locale is not available)
* @return the localized string.
*/
public static String getLocalizedString(String key, String pluginName, List<?> arguments, Locale locale, boolean fallback) {
if (pluginName == null) {
return getLocalizedString(key, arguments);
}
if (locale == null) {
locale = JiveGlobals.getLocale();
}
String i18nFile = getI18nFile(pluginName);
// Retrieve classloader from pluginName.
final XMPPServer xmppServer = XMPPServer.getInstance();
PluginManager pluginManager = xmppServer.getPluginManager();
Plugin plugin = pluginManager.getPlugin(pluginName);
if (plugin == null) {
throw new NullPointerException("Plugin could not be located: " + pluginName);
}
ClassLoader pluginClassLoader = pluginManager.getPluginClassloader(plugin);
try {
ResourceBundle bundle = ResourceBundle.getBundle(i18nFile, locale, pluginClassLoader);
return getLocalizedString(key, locale, arguments, bundle);
} catch (MissingResourceException mre) {
Locale jivesLocale = JiveGlobals.getLocale();
if (fallback && !jivesLocale.equals(locale)) {
Log.info("Could not find the requested locale. Falling back to default locale.", mre);
return getLocalizedString(key, pluginName, arguments, jivesLocale, false);
}
Log.error(mre.getMessage(), mre);
return key;
}
}
use of org.jivesoftware.openfire.container.PluginManager in project Openfire by igniterealtime.
the class CacheFactory method getClusteredCacheStrategyClassLoader.
private static ClassLoader getClusteredCacheStrategyClassLoader() {
PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
Plugin plugin = pluginManager.getPlugin("hazelcast");
if (plugin == null) {
plugin = pluginManager.getPlugin("clustering");
if (plugin == null) {
plugin = pluginManager.getPlugin("enterprise");
}
}
PluginClassLoader pluginLoader = pluginManager.getPluginClassloader(plugin);
if (pluginLoader != null) {
if (log.isDebugEnabled()) {
StringBuffer pluginLoaderDetails = new StringBuffer("Clustering plugin class loader: ");
pluginLoaderDetails.append(pluginLoader.getClass().getName());
for (URL url : pluginLoader.getURLs()) {
pluginLoaderDetails.append("\n\t").append(url.toExternalForm());
}
log.debug(pluginLoaderDetails.toString());
}
return pluginLoader;
} else {
log.warn("CacheFactory - Unable to find a Plugin that provides clustering support.");
return Thread.currentThread().getContextClassLoader();
}
}
Aggregations