/** * Set node-specific immutable settings and initialize components. This method must be called * exactly once for each instance. * * <p>Scratch space configuration is checked and initialized. * * <p>State of an instance remains not configured if exception appears. * * @param node node to configure * @param baseScratchConfiguration base scratch data space configuration, may be <code>null</code> * if node does not provide a scratch space; not existing directory pointed by this * configuration will be created * @throws IllegalStateException when trying to reconfigure already configured instance * @throws IllegalArgumentException when trying to configure node that is on different runtime/JVM * @throws ConfigurationException when configuration appears to be wrong during node scratch space * initialization (e.g. capabilities checking) * @throws FileSystemException when VFS creation or scratch initialization fails */ public synchronized void configureNode( Node node, BaseScratchSpaceConfiguration baseScratchConfiguration) throws IllegalStateException, IllegalArgumentException, FileSystemException, ConfigurationException { logger.debug("Configuring node for Data Spaces"); checkNotConfigured(); if (!NodeFactory.isNodeLocal(node)) { logger.error("Node to configure is not on the same runtime/JVM as a caller"); throw new IllegalArgumentException( "Node to configure is not on the same runtime/JVM as a caller"); } this.node = node; try { if (baseScratchConfiguration != null) { if (baseScratchConfiguration.getUrl() == null) { baseScratchConfiguration = startProActiveProviderServer(baseScratchConfiguration); } final NodeScratchSpace configuringScratchSpace = new VFSNodeScratchSpaceImpl(); configuringScratchSpace.init(node, baseScratchConfiguration); this.nodeScratchSpace = configuringScratchSpace; } configured = true; } finally { if (!configured) { tryCloseProviderServer(); // node scratch space is not configured (does not need close) for sure } } logger.debug("Node configured for Data Spaces"); }
private BaseScratchSpaceConfiguration startProActiveProviderServer( BaseScratchSpaceConfiguration baseScratchConfiguration) throws FileSystemException, ConfigurationException { final String rootPath = baseScratchConfiguration.getPath(); final File rootFile = new File(rootPath); try { if (!rootFile.isDirectory()) rootFile.mkdirs(); } catch (SecurityException x) { throw new FileSystemException(x); } try { final String serviceId = Utils.getRuntimeId(node) + '/' + Utils.getNodeId(node) + "/fileSystemServer"; providerServerDeployer = new FileSystemServerDeployer(serviceId, rootPath, true); } catch (IOException e) { throw new FileSystemException(e); } final String vfsRootURL = providerServerDeployer.getVFSRootURL(); return baseScratchConfiguration.getWithRemoteAccess(vfsRootURL); }