com.google.common.collect.Interners Java Examples

The following examples show how to use com.google.common.collect.Interners. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InternerHelper.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
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 ();
    }
}
 
Example #2
Source File: DataChangeEventQueue.java    From sofa-registry with Apache License 2.0 5 votes vote down vote up
private void handleClientOff(ClientChangeEvent event) {
    String connectId = event.getHost();
    synchronized (Interners.newWeakInterner().intern(connectId)) {
        Map<String, Publisher> pubMap = datumCache.getByConnectId(connectId);
        if (pubMap != null && !pubMap.isEmpty()) {
            LOGGER.info(
                "[{}] client off begin, connectId={}, occurTimestamp={}, all pubSize={}",
                getName(), connectId, event.getOccurredTimestamp(), pubMap.size());
            int count = 0;
            for (Publisher publisher : pubMap.values()) {
                // Only care dataInfoIds which belong to this queue
                if (!belongTo(publisher.getDataInfoId())) {
                    continue;
                }

                DataServerNode dataServerNode = DataServerNodeFactory.computeDataServerNode(
                    dataServerConfig.getLocalDataCenter(), publisher.getDataInfoId());
                //current dataCenter backup data need not unPub,it will be unPub by backup sync event
                if (DataServerConfig.IP.equals(dataServerNode.getIp())) {
                    Datum datum = new Datum(new UnPublisher(publisher.getDataInfoId(),
                        publisher.getRegisterId(), event.getOccurredTimestamp()),
                        event.getDataCenter(), event.getVersion());
                    datum.setContainsUnPub(true);
                    handleDatum(DataChangeTypeEnum.MERGE, DataSourceTypeEnum.PUB, datum);
                    count++;
                }
            }
            LOGGER
                .info(
                    "[{}] client off handle, connectId={}, occurTimestamp={}, version={}, handle pubSize={}",
                    getName(), connectId, event.getOccurredTimestamp(), event.getVersion(),
                    count);
        } else {
            LOGGER.info("[{}] no datum to handle, connectId={}", getName(), connectId);
        }
    }
}
 
Example #3
Source File: DoubleClickMetadata.java    From openrtb-doubleclick with Apache License 2.0 5 votes vote down vote up
/**
 * 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");
  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);
  countryCodes = loadCountryCodes(interner, ADX_DICT + "countries.txt");
}
 
Example #4
Source File: SimpleFileProviderBackend.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
public SimpleFileProviderBackend(Configuration conf, Path resourcePath) throws IOException {
  this.resourcePath = resourcePath;
  this.fileSystem = resourcePath.getFileSystem(conf);
  this.groupRolePrivilegeTable = HashBasedTable.create();
  this.conf = conf;
  this.configErrors = Lists.newArrayList();
  this.configWarnings = Lists.newArrayList();
  this.validators = ImmutableList.of();
  this.allowPerDatabaseSection = true;
  this.initialized = false;
  this.stringInterner = Interners.newWeakInterner();
}
 
Example #5
Source File: InternBuilderUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void interBuilderTest() {

    Interner<Integer> interners = Interners.<Integer> newBuilder()
      .concurrencyLevel(2)
      .strong().<Integer> build();

    Assert.assertNotNull(interners);
}
 
Example #6
Source File: RouterRuleCache.java    From spring-cloud-huawei with Apache License 2.0 4 votes vote down vote up
public static void refresh() {
  serviceInfoCacheMap = new ConcurrentHashMap<>();
  servicePool = Interners.newWeakInterner();
}
 
Example #7
Source File: WeakMapStringPool.java    From mongowp with Apache License 2.0 4 votes vote down vote up
public WeakMapStringPool(StringPoolPolicy heuristic) {
  super(heuristic);
  this.interner = Interners.newWeakInterner();
}
 
Example #8
Source File: BlazeInterners.java    From bazel with Apache License 2.0 4 votes vote down vote up
public static <T> Interner<T> newWeakInterner() {
  return setConcurrencyLevel(Interners.newBuilder().weak()).build();
}
 
Example #9
Source File: BlazeInterners.java    From bazel with Apache License 2.0 4 votes vote down vote up
public static <T> Interner<T> newStrongInterner() {
  return setConcurrencyLevel(Interners.newBuilder().strong()).build();
}
 
Example #10
Source File: InternerBuilderExample.java    From tutorials with MIT License 4 votes vote down vote up
public static void main(String[] args) {
    Interner<Integer> interners = Interners.<Integer> newBuilder()
      .concurrencyLevel(2)
      .strong().<Integer> build();

}