public static Interner<String> makeInterner ( final String specificPropertyName, final String defaultType ) { final String type = System.getProperty ( specificPropertyName, System.getProperty ( "org.eclipse.scada.defaultStringInterner", defaultType ) ); if ( "weak".equals ( type ) ) { return new NullSafeInterner ( Interners.<String> newWeakInterner () ); } else if ( "strong".equals ( type ) ) { return new NullSafeInterner ( Interners.<String> newStrongInterner () ); } else if ( "java".equals ( type ) ) { return new JavaStringInterner (); } else { return makeNoOpInterner (); } }
public ScriptMonitor ( final String id, final String factoryId, final Executor executor, final BundleContext context, final Interner<String> stringInterner, final EventProcessor eventProcessor, final ObjectPoolTracker<DataSource> dataSourcePoolTracker, final ObjectPoolTracker<MasterItem> masterItemPoolTracker, final ServiceTracker<ConfigurationAdministrator, ConfigurationAdministrator> caTracker ) { super ( id, factoryId, executor, context, stringInterner, eventProcessor ); this.executor = executor; this.prefix = stringInterner.intern ( factoryId + ". " + id ); //$NON-NLS-1$ this.classLoader = getClass ().getClassLoader (); this.monitorStateInjector = new MonitorStateInjector ( stringInterner ); this.monitorStateInjector.setPrefix ( this.prefix ); this.handler = new InjectMasterHandler ( id, masterItemPoolTracker, 0, caTracker, this.prefix, factoryId ); this.listener = new MultiDataSourceListener ( dataSourcePoolTracker ) { @Override protected void handleChange ( final Map<String, DataSourceHandler> sources ) { ScriptMonitor.this.handleChange ( sources ); } }; }
private static ImmutableMap<CityDMARegionKey, CityDMARegionValue> loadCitiesDMARegions( Interner<String> interner, String resourceName) { Map<CityDMARegionKey, CityDMARegionValue> map = new LinkedHashMap<>(); try (InputStream is = new ResourceTransport().open(resourceName)) { CSVParser.csvParser().parse(is, ".*,(\\d+),.*,.*,(\\d+)", fields -> { map.put( new CityDMARegionKey( Integer.parseInt(fields.get(1)), interner.intern(fields.get(3))), new CityDMARegionValue( Integer.parseInt(fields.get(4)), interner.intern(fields.get(0)), interner.intern(fields.get(2)))); return true; }); } catch (IOException e) { logger.warn(e.toString()); return ImmutableMap.of(); } return ImmutableMap.copyOf(map); }
public static Interner<String> makeNoOpInterner () { return new Interner<String> () { @Override public String intern ( final String string ) { return string; } }; }
public AbstractMasterItemMonitor ( final BundleContext context, final Executor executor, final Interner<String> stringInterner, final ObjectPoolTracker<MasterItem> poolTracker, final EventProcessor eventProcessor, final String id, final String factoryId, final String prefix, final String defaultMonitorType ) { super ( id, factoryId, executor, context, stringInterner, eventProcessor ); this.factoryId = factoryId; this.executor = executor; this.poolTracker = poolTracker; this.defaultMonitorType = defaultMonitorType; this.monitorStateInjector = new MonitorStateInjector ( stringInterner ); setPrefix ( prefix ); }
public JdbcStorageDao ( final DataSourceFactory dataSourceFactory, final Properties properties, final boolean usePool, final Long loginTimeout, final Interner<String> stringInterner ) throws SQLException { super ( dataSourceFactory, properties, usePool, loginTimeout, stringInterner ); this.executor = Executors.newSingleThreadScheduledExecutor ( new NamedThreadFactory ( "org.eclipse.scada.ae.server.storage.jdbc/CleanupThread" ) ); this.executor.scheduleWithFixedDelay ( new Runnable () { @Override public void run () { cleanupArchive (); } }, getCleanupPeriod (), getCleanupPeriod (), TimeUnit.SECONDS ); }
public AbstractMonitorService ( final String id, final Executor executor, final Interner<String> stringInterner ) { this.executor = executor; this.id = id; this.stringInterner = stringInterner == null ? InternerHelper.makeNoOpInterner () : stringInterner; this.currentState = new MonitorStatusInformation ( id, MonitorStatus.INIT, System.currentTimeMillis (), null, null, null, null, null, null, null ); }
protected String getPrefixed ( final String id, final Interner<String> stringInterner ) { if ( id == null ) { return this.prefix; } else { return stringInterner.intern ( this.dotPrefix + id ); } }
public ScriptMonitorFactory ( final BundleContext context, final Executor executor, final Interner<String> stringInterner, final EventProcessor eventProcessor, final ObjectPoolTracker<DataSource> dataSourcePoolTracker, final ObjectPoolTracker<MasterItem> masterItemPoolTracker, final ServiceTracker<ConfigurationAdministrator, ConfigurationAdministrator> caTracker, final ObjectPoolImpl<MonitorService> monitorServicePool ) { super ( context ); this.executor = executor; this.stringInterner = stringInterner; this.eventProcessor = eventProcessor; this.dataSourcePoolTracker = dataSourcePoolTracker; this.masterItemPoolTracker = masterItemPoolTracker; this.caTracker = caTracker; this.monitorServicePool = monitorServicePool; }
public ConfigurationAdminImpl ( final BundleContext context, final Interner<String> stringInterner ) throws Exception { super ( context ); this.stringInterner = stringInterner; this.context = context; initRoot (); }
public BitMonitorFactory ( final BundleContext context, final ManageableObjectPool<MonitorService> servicePool, final EventProcessor eventProcessor, final Executor executor, final Interner<String> stringInterner, final ObjectPoolTracker<MasterItem> poolTracker ) { super ( context, servicePool, eventProcessor ); this.executor = executor; this.stringInterner = stringInterner; this.poolTracker = poolTracker; }
public LevelMonitorFactory ( final BundleContext context, final ManageableObjectPool<MonitorService> servicePool, final EventProcessor eventProcessor, final Executor executor, final Interner<String> stringInterner, final ObjectPoolTracker<MasterItem> poolTracker ) { super ( context, servicePool, eventProcessor ); this.executor = executor; this.stringInterner = stringInterner; this.poolTracker = poolTracker; }
public ListMonitorFactory ( final BundleContext context, final ManageableObjectPool<MonitorService> servicePool, final EventProcessor eventProcessor, final Executor executor, final Interner<String> stringInterner, final ObjectPoolTracker<MasterItem> poolTracker ) { super ( context, servicePool, eventProcessor ); this.executor = executor; this.stringInterner = stringInterner; this.poolTracker = poolTracker; }
@Test void test() { AtomicInteger assertSize = new AtomicInteger(); BufferTrigger<Integer> bufferTrigger = SimpleBufferTrigger .<Integer, Set<Interner>> newGenericBuilder() // .triggerStrategy(new MultiIntervalTriggerStrategy() // .on(10, SECONDS, 1) // .on(5, SECONDS, 10) // .on(1, SECONDS, 100) // ) // .consumer(set -> { System.out.println("size:" + set.size()); assertEquals(set.size(), assertSize.get()); }) // .build(); enqueue(bufferTrigger, 100); assertSize.set(100); sleep(2); enqueue(bufferTrigger, 10); assertSize.set(10); sleep(6); enqueue(bufferTrigger, 1); assertSize.set(1); sleep(11); sleepUninterruptibly(10, SECONDS); }
@Test void testInvalidBuild() { assertThrows(IllegalArgumentException.class, () -> SimpleBufferTrigger.<Integer, Set<Interner>> newGenericBuilder() // .triggerStrategy(new MultiIntervalTriggerStrategy() // .on(1, SECONDS, 1) // .on(2, SECONDS, 2) // ).consumer(set -> System.out.println("size:" + set.size())) // .build()); }
/** * Split the file into a filename/directory pair. * * @param interner The interner to use for interning the strings. * @param input The input to split. * @return The pair of directory, filename. */ private FileName splitFileName( Interner<String> interner, String input) { int hashIndex = input.lastIndexOf('/'); String dir = interner.intern(input.substring(0, hashIndex + 1)); String fileName = interner.intern(input.substring(hashIndex + 1)); return new FileName(dir, fileName); }
/** * Creates the DoubleClickMetadata object. * * @param transport How to read the many files providing metadata information. * Typically you will use one of the provided implementations, * {@link URLConnectionTransport} or {@link ResourceTransport} */ @Inject public DoubleClickMetadata(Transport transport) { Pattern ssvp = Pattern.compile("(\\d+)\\s+(.*)"); Pattern csvp = Pattern.compile("(\\d+),(.*)"); Interner<String> interner = Interners.<String>newStrongInterner(); vendors = load(interner, transport, ssvp, ADX_DICT + "vendors.txt"); gdnVendors = load(interner, transport, ssvp, ADX_DICT + "gdn-vendors.txt"); HashMap<Integer, String> cats = new HashMap<>(); cats.putAll(adSensitiveCategories = load( interner, transport, ssvp, ADX_DICT + "ad-sensitive-categories.txt")); cats.putAll(adProductCategories = load( interner, transport, ssvp, ADX_DICT + "ad-product-categories.txt")); cats.putAll(adRestrictedCategories = load( interner, transport, ssvp, ADX_DICT + "ad-restricted-categories.txt")); allAdCategories = ImmutableMap.copyOf(cats); agencies = load(interner, transport, ssvp, ADX_DICT + "agencies.txt"); HashMap<Integer, String> attrs = new HashMap<>(); attrs.putAll(pubExcCreativeAttributes = load(interner, transport, ssvp, ADX_DICT + "publisher-excludable-creative-attributes.txt")); attrs.putAll(buyDecCreativeAttributes = load(interner, transport, ssvp, ADX_DICT + "buyer-declarable-creative-attributes.txt")); allCreativeAttributes = ImmutableMap.copyOf(attrs); creativeStatusCodes = load(interner, transport, ssvp, ADX_DICT + "creative-status-codes.txt"); sellerNetworks = load(interner, transport, ssvp, ADX_DICT + "seller-network-ids.txt"); siteLists = load(interner, transport, ssvp, ADX_DICT + "site-lists.txt"); contentLabels = load(interner, transport, ssvp, ADX_DICT + "content-labels.txt"); publisherVerticals = load(interner, transport, ssvp, ADX_DICT + "publisher-verticals.txt"); mobileCarriers = load(interner, transport, CSVParser.csvParser(), csvp, ADX_DICT + "mobile-carriers.csv"); geoTargetsByCriteriaId = loadGeoTargets(interner, transport, ADX_DICT + "geo-table.csv"); HashMap<GeoTarget.CanonicalKey, GeoTarget> byKey = new HashMap<>(); for (GeoTarget target : geoTargetsByCriteriaId.values()) { byKey.put(target.key(), target); } geoTargetsByCanonicalKey = ImmutableMap.copyOf(byKey); dmaRegions = loadCitiesDMARegions(interner, ADX_DICT + "cities-dma-regions.csv"); countryCodes = loadCountryCodes(interner, ADX_DICT + "countries.txt"); }
public MiruActivityInternExtern(MiruInterner<MiruIBA> ibaInterner, MiruInterner<MiruTenantId> tenantInterner, Interner<String> stringInterner, MiruTermComposer termComposer) { this.ibaInterner = ibaInterner; this.tenantInterner = tenantInterner; this.stringInterner = stringInterner; this.termComposer = termComposer; }
/** * Return a {@link LeafInterner} for a particular schema. Interner instances must not be reused for leaves of * different types, otherwise they may produce unexpected results. * * @param schema The leaf node's schema * @return An interner instance */ @Nonnull public static <T extends LeafNode<?>> Interner<T> forSchema(@Nullable final LeafSchemaNode schema) { if (schema != null) { final TypeDefinition<?> type = schema.getType(); if (type instanceof BooleanTypeDefinition || type instanceof EnumTypeDefinition || type instanceof IdentityrefTypeDefinition) { return LeafInterner::intern; } } return Objects::requireNonNull; }
@Override public void setMarkForDelete(boolean isMark) { Interner<String> interner = findInterner(); synchronized (interner.intern(playerId)) { Optional<PlayerMetadata> playerMetadataOptional = gameManager.getPlayerManager().getPlayerMetadata(playerId); if (!playerMetadataOptional.isPresent()) { return; } PlayerMetadata playerMetadata = playerMetadataOptional.get(); playerMetadata.setIsMarkedForDelete(isMark); gameManager.getPlayerManager().savePlayerMetadata(playerMetadata); } }
private Interner<String> findInterner() { Player player = gameManager.getPlayerManager().getPlayer(playerId); Interner<String> interner; if (player == null) { interner = Interners.newWeakInterner(); } else { interner = player.getInterner(); } return interner; }
private NullSafeInterner ( final Interner<String> interner ) { this.interner = interner; }
public JdbcStorageDao ( final DataSourceFactory dataSourceFactory, final Properties properties, final boolean usePool, final Long loginTimeout, final Interner<String> stringInterner ) throws SQLException { super ( dataSourceFactory, properties, usePool, loginTimeout, stringInterner ); }
public AbstractDemotingMasterItemMonitor ( final BundleContext context, final Executor executor, final Interner<String> stringInterner, final ObjectPoolTracker<MasterItem> poolTracker, final EventProcessor eventProcessor, final String id, final String factoryId, final String prefix, final String defaultMonitorType ) { super ( context, executor, stringInterner, poolTracker, eventProcessor, id, factoryId, prefix, defaultMonitorType ); }
public MonitorStateInjector ( final Interner<String> stringInterner ) { this.stringInterner = stringInterner == null ? InternerHelper.makeNoOpInterner () : stringInterner; }
public AbstractBooleanMonitor ( final BundleContext context, final Executor executor, final Interner<String> stringInterner, final ObjectPoolTracker<MasterItem> poolTracker, final EventProcessor eventProcessor, final String id, final String factoryId, final String prefix, final String defaultMonitorType ) { super ( context, executor, stringInterner, poolTracker, eventProcessor, id, factoryId, prefix, defaultMonitorType ); }
public AbstractNumericMonitor ( final BundleContext context, final Executor executor, final Interner<String> stringInterner, final ObjectPoolTracker<MasterItem> poolTracker, final EventProcessor eventProcessor, final String id, final String factoryId, final String prefix, final String defaultMonitorType ) { super ( context, executor, stringInterner, poolTracker, eventProcessor, id, factoryId, prefix, defaultMonitorType ); }
public AbstractVariantMonitor ( final BundleContext context, final Executor executor, final Interner<String> stringInterner, final ObjectPoolTracker<MasterItem> poolTracker, final EventProcessor eventProcessor, final String id, final String factoryId, final String prefix, final String defaultMonitorType ) { super ( context, executor, stringInterner, poolTracker, eventProcessor, id, factoryId, prefix, defaultMonitorType ); }
public AbstractJdbcStorageDao ( final DataSourceFactory dataSourceFactory, final Properties properties, final boolean usePool, final Long loginTimeout, final Interner<String> stringInterner ) throws SQLException { super ( dataSourceFactory, properties, usePool, loginTimeout ); this.stringInterner = stringInterner == null ? InternerHelper.makeNoOpInterner () : stringInterner; }
public AbstractStateMonitor ( final String id, final Executor executor, final Interner<String> stringInterner, final EventProcessor eventProcessor ) { super ( id, executor, stringInterner ); this.eventProcessor = eventProcessor; }
public static Interner<String> getStringInterner () { return instance.stringInterner; }
public DefaultBinaryContext ( final Charset charset, final Interner<String> stringInterner ) { this.encoder = charset.newEncoder (); this.decoder = charset.newDecoder (); this.stringInterner = stringInterner == null ? InternerHelper.makeNoOpInterner () : stringInterner; }
public BitMonitor ( final BundleContext context, final Executor executor, final Interner<String> stringInterner, final ObjectPoolTracker<MasterItem> poolTracker, final EventProcessor eventProcessor, final String id, final String prefix, final String defaultMonitorType ) { super ( context, executor, stringInterner, poolTracker, eventProcessor, id, BitMonitorFactory.FACTORY_ID, prefix, defaultMonitorType ); }
public LevelMonitor ( final BundleContext context, final Executor executor, final Interner<String> stringInterner, final ObjectPoolTracker<MasterItem> poolTracker, final EventProcessor eventProcessor, final String id, final String prefix, final String defaultMonitorType ) { super ( context, executor, stringInterner, poolTracker, eventProcessor, id, LevelMonitorFactory.FACTORY_ID, prefix, defaultMonitorType ); this.firstPrefix = prefix; }
public ListMonitor ( final BundleContext context, final Executor executor, final Interner<String> stringInterner, final ObjectPoolTracker<MasterItem> poolTracker, final EventProcessor eventProcessor, final String id, final String prefix, final String defaultMonitorType ) { super ( context, executor, stringInterner, poolTracker, eventProcessor, id, ListMonitorFactory.FACTORY_ID, prefix, defaultMonitorType ); }
/** * Creates an instance of Canonicalizer tracking path fragments. */ public static Interner<PathFragment> fragments() { return FRAGMENT_INTERNER; }
public static <T> Interner<T> newWeakInterner() { return setConcurrencyLevel(Interners.newBuilder().weak()).build(); }
public static <T> Interner<T> newStrongInterner() { return setConcurrencyLevel(Interners.newBuilder().strong()).build(); }
public AbstractPersistentStateMonitor ( final String id, final String factoryId, final Executor executor, final BundleContext context, final Interner<String> stringInterner, final EventProcessor eventProcessor ) { super ( id, executor, stringInterner, eventProcessor ); this.context = context; this.tracker = new SingleServiceTracker<DataStore> ( context, DataStore.class, this.listener ); this.nodeId = factoryId + "/" + id; this.tracker.open (); }