@UnsafeMethod public synchronized void enablePlugin(Plugin plugin) { if (!CommonPlugin.class.isAssignableFrom(plugin.getClass())) { throw new IllegalArgumentException( "Cannot enable plugin with this PluginLoader as it is of the wrong type!"); } if (!plugin.isEnabled()) { CommonPlugin cp = (CommonPlugin) plugin; String name = cp.getDescription().getName(); if (!loaders.containsKey(name)) { loaders.put(name, (CommonClassLoader) cp.getClassLoader()); } try { cp.setEnabled(true); cp.onEnable(); } catch (Throwable e) { engine .getLogger() .log( Level.SEVERE, "An error occured when enabling '" + plugin.getDescription().getFullName() + "': " + e.getMessage(), e); } engine.getEventManager().callEvent(new PluginEnableEvent(cp)); } }
/** * @param file Plugin file object * @return The current plugin's description element. * @throws InvalidPluginException * @throws InvalidDescriptionFileException */ protected synchronized PluginDescriptionFile getDescription(File file) throws InvalidPluginException, InvalidDescriptionFileException { if (!file.exists()) { throw new InvalidPluginException(file.getName() + " does not exist!"); } PluginDescriptionFile description = null; JarFile jar = null; InputStream in = null; try { // Spout plugin properties file jar = new JarFile(file); JarEntry entry = jar.getJarEntry(YAML_SPOUT); // Fallback plugin properties file if (entry == null) { entry = jar.getJarEntry(YAML_OTHER); } if (entry == null) { throw new InvalidPluginException("Jar has no properties.yml or plugin.yml!"); } in = jar.getInputStream(entry); description = new PluginDescriptionFile(in); } catch (IOException e) { throw new InvalidPluginException(e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { engine.getLogger().log(Level.WARNING, "Problem closing input stream", e); } } if (jar != null) { try { jar.close(); } catch (IOException e) { engine.getLogger().log(Level.WARNING, "Problem closing jar input stream", e); } } } return description; }
public SpoutParallelTaskManager(Engine engine) { if (engine == null) { throw new IllegalArgumentException("Engine cannot be set to null"); } upTime = new AtomicLong(0); this.engine = engine; this.world = null; this.scheduler = engine.getScheduler(); }
public synchronized Plugin loadPlugin(File paramFile, boolean ignoresoftdepends) throws InvalidPluginException, UnknownDependencyException, InvalidDescriptionFileException { CommonPlugin result; PluginDescriptionFile desc; CommonClassLoader loader; desc = getDescription(paramFile); File dataFolder = new File(paramFile.getParentFile(), desc.getName()); processDependencies(desc); if (!ignoresoftdepends) { processSoftDependencies(desc); } try { if (engine.getPlatform() == Platform.CLIENT) { loader = new ClientClassLoader(this, this.getClass().getClassLoader()); } else { loader = new CommonClassLoader(this, this.getClass().getClassLoader()); } loader.addURL(paramFile.toURI().toURL()); Class<?> main = Class.forName(desc.getMain(), true, loader); Class<? extends CommonPlugin> plugin = main.asSubclass(CommonPlugin.class); boolean locked = manager.lock(key); Constructor<? extends CommonPlugin> constructor = plugin.getConstructor(); result = constructor.newInstance(); result.initialize(this, engine, desc, dataFolder, paramFile, loader); if (!locked) { manager.unlock(key); } } catch (Exception e) { throw new InvalidPluginException(e); } loader.setPlugin(result); loaders.put(desc.getName(), loader); return result; }
public void heartbeat(long delta) { if (engine != null) { TickStage.checkStage(TickStage.TICKSTART); } else { TickStage.checkStage(TickStage.STAGE1); } SpoutRegion region; SpoutTask task; while ((task = newTasks.poll()) != null) { int taskId = task.getTaskId(); ParallelTaskInfo info = activeTasks.get(taskId); if (info == null) { info = new ParallelTaskInfo(task); ParallelTaskInfo previous = activeTasks.putIfAbsent(taskId, info); if (previous != null) { info = previous; } task.setParallelInfo(info); } Collection<? extends World> worlds = (this.world == null) ? engine.getWorlds() : world; for (World w : worlds) { SpoutWorld sw = (SpoutWorld) w; for (Region r : sw.getRegions()) { info.add((SpoutRegion) r); } } } while ((region = newRegions.poll()) != null) { for (ParallelTaskInfo info : activeTasks.values(ParallelTaskInfo.EMPTY_ARRAY)) { info.add(region); } } while ((region = deadRegions.poll()) != null) { while (newRegions.remove(region)) {; } for (ParallelTaskInfo info : activeTasks.values(ParallelTaskInfo.EMPTY_ARRAY)) { while (info.remove(region)) {; } } } }