use of jgnash.engine.message.MessageBus in project jgnash by ccavanaugh.
the class UIApplication method restartUI.
/**
* Forces a restart of the UI without having to reload the engine. Useful when changing the look and feel
*/
public static void restartUI() {
EventQueue.invokeLater(() -> {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
if (engine != null) {
MessageBus messageBus = MessageBus.getInstance(engine.getName());
Message message = new Message(MessageChannel.SYSTEM, ChannelEvent.UI_RESTARTING, engine);
messageBus.fireEvent(message);
}
mainFrame.setVisible(false);
mainFrame.doPartialDispose();
// recreate the main UI twice to flush look and feel info from the JXSwing components
mainFrame = new MainFrame();
mainFrame.doPartialDispose();
mainFrame = new MainFrame();
mainFrame.setVisible(true);
if (engine != null) {
MessageBus messageBus = MessageBus.getInstance(engine.getName());
Message message = new Message(MessageChannel.SYSTEM, ChannelEvent.UI_RESTARTED, engine);
messageBus.fireEvent(message);
}
});
}
use of jgnash.engine.message.MessageBus in project jgnash by ccavanaugh.
the class EngineFactory method bootClientEngine.
public static synchronized Engine bootClientEngine(final String host, final int port, final char[] password, final String engineName) throws Exception {
if (engineMap.get(engineName) != null) {
throw new RuntimeException("A stale engine was found in the map");
}
final Preferences pref = Preferences.userNodeForPackage(EngineFactory.class);
Engine engine = null;
// start the client message bus
if (MessageBus.getInstance(engineName).setRemote(host, port + JpaNetworkServer.MESSAGE_SERVER_INCREMENT, password)) {
pref.putInt(LAST_PORT, port);
pref.put(LAST_HOST, host);
pref.putBoolean(LAST_REMOTE, true);
final MessageBus messageBus = MessageBus.getInstance(engineName);
// after starting the remote message bus, it should receive the path on the server
final String remoteDataBasePath = messageBus.getRemoteDataBasePath();
final DataStoreType dataStoreType = messageBus.getRemoteDataStoreType();
if (remoteDataBasePath == null || remoteDataBasePath.isEmpty() || dataStoreType == null) {
throw new Exception("Invalid connection wih the message bus");
}
logger.log(Level.INFO, "Remote path was {0}", remoteDataBasePath);
logger.log(Level.INFO, "Remote data store was {0}", dataStoreType.name());
logger.log(Level.INFO, "Engine name was {0}", engineName);
DataStore dataStore = dataStoreType.getDataStore();
// connect to the remote server
engine = dataStore.getClientEngine(host, port, password, remoteDataBasePath);
if (engine != null) {
logger.info(ResourceUtils.getString("Message.EngineStart"));
engineMap.put(engineName, engine);
dataStoreMap.put(engineName, dataStore);
// remember if the user used a password for the last session
pref.putBoolean(USED_PASSWORD, password.length > 0);
final Message message = new Message(MessageChannel.SYSTEM, ChannelEvent.FILE_LOAD_SUCCESS, engine);
MessageBus.getInstance(engineName).fireEvent(message);
}
}
return engine;
}
Aggregations