Example usage for com.google.common.collect Sets newConcurrentHashSet

List of usage examples for com.google.common.collect Sets newConcurrentHashSet

Introduction

In this page you can find the example usage for com.google.common.collect Sets newConcurrentHashSet.

Prototype

public static <E> Set<E> newConcurrentHashSet() 

Source Link

Document

Creates a thread-safe set backed by a hash map.

Usage

From source file:org.restcomm.media.control.mgcp.network.nio.MgcpChannel.java

public MgcpChannel(NetworkGuard networkGuard, MgcpPacketHandler packetHandler) {
    super(networkGuard, packetHandler);

    // Packet Handlers
    this.mgcpHandler = packetHandler;
    this.mgcpHandler.observe(this);

    // Observers//from   w  w w .ja  v a2s .  c om
    this.observers = Sets.newConcurrentHashSet();
}

From source file:com.github.hilcode.versionator.ListExecutor.java

public final void execute() {
    final File rootDir_ = this.commandList.rootDir.getAbsoluteFile();
    final File rootDir = rootDir_.getPath().endsWith(".") ? rootDir_.getParentFile() : rootDir_;
    final ImmutableList<Pom> poms = this.pomFinder.findAllPoms(rootDir);
    final Set<PomAndGav> pomAndGavs = Sets.newConcurrentHashSet();
    for (final Pom pom : poms) {
        if (pom.parent.isPresent()) {
            final Pom parent = pom.parent.get();
            boolean includeGav = this.commandList.patterns.get(0).startsWith("!");
            for (final String pattern : this.commandList.patterns) {
                final boolean exclusion = pattern.startsWith("!");
                final Glob glob = exclusion ? Globs.create(pattern.substring(1)) : Globs.create(pattern);
                if (exclusion) {
                    if (glob.match(parent.gav.toText())) {
                        includeGav = false;
                    }//  w ww. j  a  v a 2s.  co m
                } else {
                    if (glob.match(parent.gav.toText())) {
                        includeGav = true;
                    }
                }
            }
            if (includeGav) {
                pomAndGavs.add(new PomAndGav(pom, parent.gav));
            }
        }
        final Document pomDocument = this.pomParser.toDocument(pom.file);
        final ImmutableList<Dependency> dependencies = this.pomParser.findDependencies(pomDocument);
        for (final Dependency dependency : dependencies) {
            boolean includeGav = this.commandList.patterns.get(0).startsWith("!");
            for (final String pattern : this.commandList.patterns) {
                final boolean exclusion = pattern.startsWith("!");
                final Glob glob = exclusion ? Globs.create(pattern.substring(1)) : Globs.create(pattern);
                if (exclusion) {
                    if (glob.match(dependency.gav.toText())) {
                        includeGav = false;
                    }
                } else {
                    if (glob.match(dependency.gav.toText())) {
                        includeGav = true;
                    }
                }
            }
            if (includeGav) {
                pomAndGavs.add(new PomAndGav(pom, dependency.gav));
            }
        }
    }
    final List<PomAndGav> pomAndGavs_ = Lists.newArrayList(pomAndGavs);
    Collections.sort(pomAndGavs_);
    if (this.commandList.grouping == Command.Grouping.BY_POM) {
        final List<Pom> poms_ = Lists.newArrayList();
        final Map<Pom, List<Gav>> map = Maps.newConcurrentMap();
        for (final PomAndGav pomAndGav : pomAndGavs_) {
            if (!map.containsKey(pomAndGav.pom)) {
                poms_.add(pomAndGav.pom);
                map.put(pomAndGav.pom, Lists.<Gav>newArrayList());
            }
            map.get(pomAndGav.pom).add(pomAndGav.gav);
        }
        Collections.sort(poms_);
        final String pomMask = "%" + (1 + (int) Math.floor(Math.log10(poms_.size()))) + "d) %s (%s)";
        int pomIndex = 0;
        for (final Pom pom : poms_) {
            if (pomIndex != 0) {
                System.out.println();
            }
            pomIndex++;
            final File relativePomFile = new File(
                    pom.file.getPath().substring(rootDir.getAbsolutePath().length() + 1));
            System.out.println(
                    String.format(pomMask, Integer.valueOf(pomIndex), pom.gav.toText(), relativePomFile));
            final List<Gav> gavs = map.get(pom);
            final String gavMask = "    %" + (1 + (int) Math.floor(Math.log10(gavs.size()))) + "d) %s";
            int gavIndex = 0;
            for (final Gav gav : gavs) {
                gavIndex++;
                System.out.println(String.format(gavMask, Integer.valueOf(gavIndex), gav.toText()));
            }
        }
    } else {
        if (this.commandList.verbosity == Command.Verbosity.VERBOSE) {
            final List<GroupArtifact> groupArtifacts = Lists.newArrayList();
            final Map<GroupArtifact, Set<Pom>> map = Maps.newConcurrentMap();
            int maxLength = 0;
            int maxGroupSize = 0;
            for (final PomAndGav gavAndPom : pomAndGavs_) {
                final GroupArtifact groupArtifact = gavAndPom.gav.groupArtifact;
                if (!map.containsKey(groupArtifact)) {
                    groupArtifacts.add(groupArtifact);
                    map.put(groupArtifact, Sets.<Pom>newConcurrentHashSet());
                }
                map.get(groupArtifact).add(gavAndPom.pom);
                final int groupSize = map.get(groupArtifact).size();
                if (groupSize > maxGroupSize) {
                    maxGroupSize = groupSize;
                }
                final int length = gavAndPom.pom.gav.groupArtifact.toText().length();
                if (length > maxLength) {
                    maxLength = length;
                }
            }
            final int maxGroupLength = 1 + (int) Math.floor(Math.log10(maxGroupSize));
            Collections.sort(groupArtifacts);
            final String groupArtifactMask = "%" + (1 + (int) Math.floor(Math.log10(groupArtifacts.size())))
                    + "d) %s";
            int groupArtifactIndex = 0;
            final String pomMask = "    %" + maxGroupLength + "d) %-" + maxLength + "s   %s";
            for (final GroupArtifact groupArtifact : groupArtifacts) {
                if (groupArtifactIndex != 0) {
                    System.out.println();
                }
                groupArtifactIndex++;
                System.out.println(String.format(groupArtifactMask, Integer.valueOf(groupArtifactIndex),
                        groupArtifact.toText()));
                final List<Pom> poms_ = Lists.newArrayList(map.get(groupArtifact));
                Collections.sort(poms_);
                int pomIndex = 0;
                for (final Pom pom : poms_) {
                    pomIndex++;
                    final File relativePomFile = new File(
                            pom.file.getPath().substring(rootDir.getAbsolutePath().length() + 1));
                    System.out.println(String.format(pomMask, Integer.valueOf(pomIndex),
                            pom.gav.groupArtifact.toText(), relativePomFile));
                }
            }
        } else {
            final List<Gav> gavs = Lists.newArrayList();
            final Set<Gav> gavsSeen = Sets.newConcurrentHashSet();
            for (final PomAndGav gavAndPom : pomAndGavs_) {
                final Gav gav = gavAndPom.gav;
                if (!gavsSeen.contains(gav)) {
                    gavs.add(gav);
                    gavsSeen.add(gav);
                }
            }
            Collections.sort(gavs);
            final String gavMask = "%" + (1 + (int) Math.floor(Math.log10(gavs.size()))) + "d) %s";
            int gavIndex = 0;
            for (final Gav gav : gavs) {
                gavIndex++;
                System.out.println(String.format(gavMask, Integer.valueOf(gavIndex), gav.toText()));
            }
        }
    }
}

From source file:org.onosproject.icona.domainmgr.impl.config.DomainConfig.java

/**
 * Gets the remote domain identifiers.//  www .j ava 2 s  . c o  m
 * @return set of domain IDs
 */
public Set<DomainId> remoteDomainIds() {
    Set<DomainId> remoteDomainIds = Sets.newConcurrentHashSet();
    object.path(REMOTE_DOMAINS)
            .forEach(domainElem -> remoteDomainIds.add(new DomainId(domainElem.path(DOMAIN_ID).asText())));
    return ImmutableSet.copyOf(remoteDomainIds);
}

From source file:org.restcomm.media.control.mgcp.network.nio.MgcpPacketHandler.java

public MgcpPacketHandler(MgcpMessageParser parser) {
    this.parser = parser;
    this.observers = Sets.newConcurrentHashSet();
}

From source file:oims.dataBase.syncer.DataBaseSyncer.java

private Set<String> checkSyncerTable() {
    Set<String> tableNeedDownload = Sets.newConcurrentHashSet();
    if (this.itsDbm_.isRemoteDbConnected() && this.itsDbm_.islocalDbConnected()) {
        ResultSet localRs = this.itsDbm_.getlocalSnycerTable();
        ResultSet remoteRs = this.itsDbm_.getRemoteSnycerTable();
        tableNeedDownload = this.itsSyncerTable_.compareSyncerTable(localRs, remoteRs);
    }/*from ww w.ja  v  a2  s . c om*/
    return tableNeedDownload;
}

From source file:org.restcomm.media.control.mgcp.endpoint.MgcpEndpointManager.java

public MgcpEndpointManager() {
    // Endpoint Management
    this.endpoints = new ConcurrentHashMap<>(100);
    this.providers = new ConcurrentHashMap<>(5);

    // Message Passing
    this.observers = Sets.newConcurrentHashSet();
}

From source file:com.navercorp.nbasearc.gcp.GatewayConnectionPool.java

public GatewayConnectionPool(int threadPoolSize, boolean healthCheckUsed) {
    this.eventLoopTrunk = new SingleThreadEventLoopTrunk(threadPoolSize);
    this.gwMap = new ConcurrentHashMap<Integer, Gateway>();
    this.vcConcurrentSet = Sets.newConcurrentHashSet();
    this.closed = new AtomicBoolean();
    this.affinity = new Affinity();
    this.roundGatewayIndex = new AtomicInteger(0);
    this.gatewayList = new AtomicReference<List<Gateway>>();
    this.random = new Random(System.currentTimeMillis());

    if (healthCheckUsed) {
        this.eventLoopTrunk.roundrobinEventLoop().getEventLoopGroup().scheduleAtFixedRate(healthCheckJob, 1, 1,
                TimeUnit.SECONDS);
    }//from   w  w w  . j  a v  a 2s  .co m
}

From source file:org.onosproject.ecord.carrierethernet.app.CarrierEthernetInni.java

@Deprecated
public CarrierEthernetInni(ConnectPoint connectPoint, String uniCfgId, Role role, VlanId sVlanId, String tpid,
        Bandwidth usedCapacity) {/*from  w  ww.j av a2  s .  c  o m*/

    super(connectPoint, Type.INNI, uniCfgId);

    // TODO: Check for null
    this.role = role;
    this.sVlanIdSet = Sets.newConcurrentHashSet();
    // The following applies only to service-specific INNIs
    if (sVlanId != null) {
        this.sVlanIdSet.add(sVlanId);
        // TODO: Use role correctly
        this.role = Role.HUB;
        this.usedCapacity = usedCapacity;
        this.tpid = tpid;
    }
}

From source file:gobblin.metrics.RootMetricContext.java

private RootMetricContext(List<Tag<?>> tags) throws NameConflictException {
    super(ROOT_METRIC_CONTEXT, null, tags, true);
    this.innerMetricContexts = Sets.newConcurrentHashSet();
    this.referenceQueue = new ReferenceQueue<>();
    this.referenceQueueExecutorService = ExecutorsUtils.loggingDecorator(
            MoreExecutors.getExitingScheduledExecutorService(new ScheduledThreadPoolExecutor(1, ExecutorsUtils
                    .newThreadFactory(Optional.of(log), Optional.of("GobblinMetrics-ReferenceQueue")))));
    this.referenceQueueExecutorService.scheduleWithFixedDelay(new CheckReferenceQueue(), 0, 2,
            TimeUnit.SECONDS);/*w  w w . j  a  va  2  s .  c o m*/

    this.reporters = Sets.newConcurrentHashSet();
    this.reportingStarted = false;

    addShutdownHook();
}

From source file:org.apache.pulsar.client.api.TlsProducerConsumerBase.java

protected void internalSetUpForBroker() throws Exception {
    conf.setBrokerServicePortTls(BROKER_PORT_TLS);
    conf.setWebServicePortTls(BROKER_WEBSERVICE_PORT_TLS);
    conf.setTlsCertificateFilePath(TLS_SERVER_CERT_FILE_PATH);
    conf.setTlsKeyFilePath(TLS_SERVER_KEY_FILE_PATH);
    conf.setTlsTrustCertsFilePath(TLS_TRUST_CERT_FILE_PATH);
    conf.setClusterName(clusterName);// w w  w.java 2  s.c o  m
    conf.setTlsRequireTrustedClientCertOnConnect(true);
    Set<String> tlsProtocols = Sets.newConcurrentHashSet();
    tlsProtocols.add("TLSv1.2");
    conf.setTlsProtocols(tlsProtocols);
}