/** * Creates a new {@link Domain} containing a default {@link Configuration}. {@link ArchiveFactory}s created from * this domain will have isolated configuration from archive factories created from other domains. Likewise, all * {@link ArchiveFactory}s and {@link Archive}s created from the returned domain will share the same configuration. * * @return A new {@link Domain} with default configuration */ public static Domain createDomain() { return createDomain(new ConfigurationBuilder()); }
/** * Creates a new {@link Domain} containing a default {@link Configuration}. {@link ArchiveFactory}s created from * this domain will have isolated configuration from archive factories created from other domains. Likewise, all * {@link ArchiveFactory}s and {@link Archive}s created from the returned domain will share the same configuration. * * @return A new {@link Domain} with default configuration */ public static Domain createDomain() { return createDomain(new ConfigurationBuilder()); }
protected static void writeLimits(Network network, EurostagDictionary dictionary, OutputStream os, EurostagEchExportConfig exportConfig) throws IOException { writeLimits(network, dictionary, ShrinkWrap.createDomain(), os, exportConfig); }
public GenericArchive writeFaultSeqArchive(List<Contingency> contingencies, Network network, EurostagDictionary dictionary, Function<Integer, String> seqFileNameFct) throws IOException { return writeFaultSeqArchive(ShrinkWrap.createDomain(), contingencies, network, dictionary, seqFileNameFct); }
/** * Creates a new {@link Domain} containing configuration properties from the supplied {@link ConfigurationBuilder}. * {@link ArchiveFactory}s created from this domain will have isolated configuration from archive factories created * from other domains. Likewise, all {@link ArchiveFactory}s and {@link Archive}s created from the returned domain * will share the same configuration. * * @param builder * Builder with which we should create a {@link Configuration} for this {@link Domain} * @return A new {@link Domain} with default configuration * @throws IllegalArgumentException * If the builder is not supplied */ public static Domain createDomain(final ConfigurationBuilder builder) throws IllegalArgumentException { if (builder == null) { throw new IllegalArgumentException("builder must be supplied"); } return createDomain(builder.build()); }
/** * Creates a new {@link Domain} containing configuration properties from the supplied {@link ConfigurationBuilder}. * {@link ArchiveFactory}s created from this domain will have isolated configuration from archive factories created * from other domains. Likewise, all {@link ArchiveFactory}s and {@link Archive}s created from the returned domain * will share the same configuration. * * @param builder * Builder with which we should create a {@link Configuration} for this {@link Domain} * @return A new {@link Domain} with default configuration * @throws IllegalArgumentException * If the builder is not supplied */ public static Domain createDomain(final ConfigurationBuilder builder) throws IllegalArgumentException { if (builder == null) { throw new IllegalArgumentException("builder must be supplied"); } return createDomain(builder.build()); }
Server(final InetSocketAddress bindAddress) { // Precondition checks assert bindAddress != null : "Bind address must be specified"; // Determine the ClassLoader to use in creating the SW Domain final ClassLoader thisCl = Server.class.getClassLoader(); final Set<ClassLoader> classloaders = new HashSet<>(1); classloaders.add(thisCl); if (Server.log.isLoggable(Level.FINEST)) { Server.log.finest("Using ClassLoader for ShrinkWrap Domain: " + thisCl); } this.shrinkwrapDomain = ShrinkWrap.createDomain(new ConfigurationBuilder().classLoaders(classloaders)); // Set this.bindAddress = bindAddress; }
Server(final InetSocketAddress bindAddress, ClassLoader classLoader) { // Precondition checks assert bindAddress != null : "Bind address must be specified"; // Determine the ClassLoader to use in creating the SW Domain final ClassLoader thisCl = Server.class.getClassLoader(); final Set<ClassLoader> classloaders = new HashSet<>(1); classloaders.add(thisCl); if (Server.log.isLoggable(Level.FINEST)) { Server.log.finest("Using ClassLoader for ShrinkWrap Domain: " + thisCl); } final Domain shrinkwrapDomain = ShrinkWrap.createDomain(new ConfigurationBuilder().classLoaders(classloaders)); // Set this.bindAddress = bindAddress; this.deployedArchives = new ConcurrentHashMap<>(); this.shrinkwrapDomain = shrinkwrapDomain; this.classLoader = classLoader; }
/** * Creates a new instance, to be bound on start at the specified, required {@link InetSocketAddress} * * @param bindAddress */ public ServerBase(final InetSocketAddress bindAddress) { // Precondition checks assert bindAddress != null : "Bind address must be specified"; // Determine the ClassLoader to use in creating the SW Domain final ClassLoader thisCl = NettyServer.class.getClassLoader(); final Set<ClassLoader> classloaders = new HashSet<ClassLoader>(1); classloaders.add(thisCl); if (log.isLoggable(Level.FINEST)) { log.finest("Using ClassLoader for ShrinkWrap Domain: " + thisCl); } final Domain shrinkwrapDomain = ShrinkWrap.createDomain(new ConfigurationBuilder().classLoaders(classloaders)); // Set this.bindAddress = bindAddress; this.deployedArchives = new ConcurrentHashMap<String, GenericArchive>(); this.shrinkwrapDomain = shrinkwrapDomain; }
/** * Ensures we cannot create a new {@link Domain} with null {@link Configuration} specified */ @Test(expected = IllegalArgumentException.class) public void newDomainRequiresConfiguration() { ShrinkWrap.createDomain((Configuration) null); }
/** * Ensures we cannot create a new {@link Domain} with null {@link ConfigurationBuilder} specified */ @Test(expected = IllegalArgumentException.class) public void newDomainRequiresConfigurationBuilder() { ShrinkWrap.createDomain((ConfigurationBuilder) null); }
@Override public void init(SimulationParameters parameters, Map<String, Object> context) throws Exception { Objects.requireNonNull(parameters, "parameters is null"); Objects.requireNonNull(context, "context is null"); this.parameters = parameters; // exportConfig = new EurostagEchExportConfig(config.isLfNoGeneratorMinMaxQ()); // isLfNoGeneratorMinMaxQ must now be configured in eurostag-ech-export section exportConfig = EurostagEchExportConfig.load(); fakeNodes = EurostagFakeNodes.build(network, exportConfig); parallelIndexes = BranchParallelIndexes.build(network, exportConfig, fakeNodes); // fill iTesla id to Esg id dictionary dictionary = EurostagDictionary.create(network, parallelIndexes, exportConfig, fakeNodes); if (config.isUseBroadcast()) { Domain domain = ShrinkWrap.createDomain(); try (OutputStream ddbOs = computationManager.newCommonFile(DDB_ZIP_FILE_NAME); OutputStream dictGensOs = computationManager.newCommonFile(DDB_DICT_GENS_CSV)) { writeDtaAndControls(domain, ddbOs, dictGensOs); } try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(computationManager.newCommonFile(PRE_FAULT_SEQ_FILE_NAME), StandardCharsets.UTF_8))) { writePreFaultSeq(writer); } } context.put("dictionary", dictionary); }
public static VDBArchive archiveFromCurrentApp() throws Exception { Configuration config = ShrinkWrap.getDefaultDomain().getConfiguration(); ArrayList<ClassLoader> existing = new ArrayList<>(); Iterator<ClassLoader> it = config.getClassLoaders().iterator(); while (it.hasNext()) { existing.add(it.next()); } existing.add(VDBArchive.class.getClassLoader()); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.classLoaders(existing); builder.extensionLoader(new ServiceExtensionLoader(existing)); Domain domain = ShrinkWrap.createDomain(builder); final VDBArchive archive = domain.getArchiveFactory().create(VDBArchive.class, determineName()); //final VDBArchive archive = ShrinkWrap.create(VDBArchive.class, determineName()); final DefaultDeploymentFactory factory = new DefaultVDBDeploymentFactory(); factory.setup(archive); archive.addAllDependencies(); return archive; }
@Override public void init(SimulationParameters parameters, Map<String, Object> context) throws Exception { Objects.requireNonNull(parameters, "parameters is null"); Objects.requireNonNull(context, "context is null"); this.parameters = parameters; dictionary = getDictionary(context); // read all contingencies allContingencies.addAll(contingenciesProvider.getContingencies(network)); if (config.isUseBroadcast()) { Domain domain = ShrinkWrap.createDomain(); try (OutputStream os = computationManager.newCommonFile(ALL_SCENARIOS_ZIP_FILE_NAME)) { writeAllScenarios(domain, os); } try (OutputStream os = computationManager.newCommonFile(WP43_ALL_CONFIGS_ZIP_FILE_NAME)) { writeAllWp43Configs(domain, os); } try (OutputStream os = computationManager.newCommonFile(LIMITS_ZIP_FILE_NAME)) { writeLimits(network, dictionary, domain, os, exportConfig); } } }
@Before public void setUp() throws IOException { Archive<?> archive = buildArchive(); tempFile = File.createTempFile("test", archive instanceof WebArchive ? ".war" : ".jar"); archive.as(ZipExporter.class).exportTo(tempFile, true); URL archiveUrl = tempFile.toURI().toURL(); URLClassLoader archiveCl = buildArchiveClassLoader(archiveUrl); ClassLoader shrinkwrapCl = new FilteringClassLoader(this.getClass().getClassLoader()); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.classLoaders(Arrays.asList(archiveCl, shrinkwrapCl)); // Create a domain that includes the `donotchange` classes within a .jar/.war // and the rest, excluding `donotchange` from the regular app classloader. this.domain = ShrinkWrap.createDomain(builder.build()); }
/** * Ensures that we can create a new {@link Domain} with explicit {@link ConfigurationBuilder} */ @Test public void createDomainWithExplicitConfigurationBuilder() { // Define configuration properties final ExecutorService service = Executors.newSingleThreadExecutor(); final ExtensionLoader loader = new MockExtensionLoader(); // Create a new domain using these config props in a builder final Domain domain = ShrinkWrap.createDomain(new ConfigurationBuilder().executorService(service) .extensionLoader(loader)); // Test TestCase.assertEquals(ExecutorService.class.getSimpleName() + " specified was not contained in resultant " + Domain.class.getSimpleName(), service, domain.getConfiguration().getExecutorService()); TestCase.assertEquals(ExtensionLoader.class.getSimpleName() + " specified was not contained in resultant " + Domain.class.getSimpleName(), loader, domain.getConfiguration().getExtensionLoader()); }
/** * Ensures that we can create a new {@link Domain} with explicit {@link Configuration} */ @Test public void createDomainWithExplicitConfiguration() { // Define configuration properties final ExecutorService service = Executors.newSingleThreadExecutor(); final ExtensionLoader loader = new MockExtensionLoader(); // Create a new domain using these config props in a config final Domain domain = ShrinkWrap.createDomain(new ConfigurationBuilder().executorService(service) .extensionLoader(loader).build()); // Test TestCase.assertEquals(ExecutorService.class.getSimpleName() + " specified was not contained in resultant " + Domain.class.getSimpleName(), service, domain.getConfiguration().getExecutorService()); TestCase.assertEquals(ExtensionLoader.class.getSimpleName() + " specified was not contained in resultant " + Domain.class.getSimpleName(), loader, domain.getConfiguration().getExtensionLoader()); }
/** * Ensures that we may add extension overrides via the {@link ExtensionLoader} through some new {@link Domain} * * @throws Exception */ @Test public void shouldBeAbleToAddOverride() throws Exception { final Domain domain = ShrinkWrap.createDomain(); domain.getConfiguration().getExtensionLoader().addOverride(JavaArchive.class, MockJavaArchiveImpl.class); final JavaArchive archive = domain.getArchiveFactory().create(JavaArchive.class, "test.jar"); Assert.assertEquals("Should have overridden normal JavaArchive impl", MockJavaArchiveImpl.class, archive.getClass()); }
/** * {@inheritDoc} * * @see org.jboss.shrinkwrap.api.Archive#shallowCopy(Filter) */ @Override public Archive<T> shallowCopy(Filter<ArchivePath> filter) { Validate.notNull(filter, "Filter must be specified"); // Get the actual class type and make a shallow copy of the the underlying archive, // using the same underlying configuration final Class<T> actualClass = this.getActualClass(); final Archive<?> underlyingArchive = this.getArchive(); final Configuration existingConfig = ((Configurable) underlyingArchive).getConfiguration(); final Domain domain = ShrinkWrap.createDomain(existingConfig); final ArchiveFactory factory = domain.getArchiveFactory(); final Archive<T> newArchive = factory.create(actualClass, this.getName()); final Map<ArchivePath, Node> contents = underlyingArchive.getContent(); for (final ArchivePath path : contents.keySet()) { Asset asset = contents.get(path).getAsset(); if (asset != null) { if(!filter.include(path)) { continue; } newArchive.add(asset, path); } } return newArchive; }
/** * Ensures that we can create isolated {@link Domain}s */ @Test public void createIsolatedDomains() { // Make a couple domains final Domain domain1 = ShrinkWrap.createDomain(); final Domain domain2 = ShrinkWrap.createDomain(); // Ensure they exist TestCase.assertNotNull("Domain should exist", domain1); TestCase.assertNotNull("Domain should exist", domain2); // Ensure they're not equal TestCase.assertNotSame("Creation of domains should return new instances", domain1, domain2); // Ensure the underlying configs are not equal TestCase.assertNotSame("Creation of domains should have unique / isolated configurations", domain1.getConfiguration(), domain2.getConfiguration()); }