Java Code Examples for java.util.Collections#synchronizedMap()

The following examples show how to use java.util.Collections#synchronizedMap() . 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: WatchDog.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 *Constructor for the WatchDog object
 *
 * @param  graph   Description of the Parameter
 * @param  phases  Description of the Parameter
 * @since          September 02, 2003
 */
public WatchDog(TransformationGraph graph, GraphRuntimeContext runtimeContext) {
	graph.setWatchDog(this);
	this.graph = graph;
	this.runtimeContext = runtimeContext;
	currentPhase = null;
	watchDogStatus = Result.N_A;
       
	inMsgQueue = new LinkedBlockingQueue<Message<?>>();
	outMsgMap = new MultiValueMap<IGraphElement, Message<?>>(Collections.synchronizedMap(new HashMap<IGraphElement, List<Message<?>>>()));
       
       //is JMX turned on?
       provideJMX = runtimeContext.useJMX();
       
       //passes a password from context to the running graph
}
 
Example 2
Source File: ProcessController.java    From ironjacamar with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Default constructor
 */
private ProcessController()
{
   this.instances = Collections.synchronizedMap(new HashMap<String, Process>());

   Runtime.getRuntime().addShutdownHook(new Thread()
   {
      @Override
      public void run()
      {
         for (Process p : instances.values())
         {
            try
            {
               p.destroy();
            }
            catch (Throwable t)
            {
               // Ignore
            }
         }
      }
   });
}
 
Example 3
Source File: Collections2Test.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.util.Collections#synchronizedMap(java.util.Map)
 */
public void test_synchronizedMapLjava_util_Map() {
    try {
        // Regression for HARMONY-93
        Collections.synchronizedMap(null);
        fail("Assert 0: synchronizedMap(map) must throw NPE");
    } catch (NullPointerException e) {
        // expected
    }
}
 
Example 4
Source File: RemotePipelineEngine.java    From hop with Apache License 2.0 5 votes vote down vote up
public RemotePipelineEngine() {
  super();
  logChannel = LogChannel.GENERAL;
  engineMetrics = new EngineMetrics();
  executionStartedListeners = Collections.synchronizedList( new ArrayList<>() );
  executionFinishedListeners = Collections.synchronizedList( new ArrayList<>() );
  executionStoppedListeners = Collections.synchronizedList( new ArrayList<>() );
  activeSubPipelines = new HashMap<>();
  activeSubWorkflows = new HashMap<>();
  engineCapabilities = new RemotePipelineEngineCapabilities();
  extensionDataMap = Collections.synchronizedMap( new HashMap<>() );
}
 
Example 5
Source File: ORBImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public synchronized void setTypeCodeForClass(Class c, TypeCodeImpl tci)
{
    checkShutdownState();

    if (typeCodeForClassMap == null)
        typeCodeForClassMap = Collections.synchronizedMap(
            new WeakHashMap(64));
    // Store only one TypeCode per class.
    if ( ! typeCodeForClassMap.containsKey(c))
        typeCodeForClassMap.put(c, tci);
}
 
Example 6
Source File: ORBImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public synchronized void setTypeCodeForClass(Class c, TypeCodeImpl tci)
{
    checkShutdownState();

    if (typeCodeForClassMap == null)
        typeCodeForClassMap = Collections.synchronizedMap(
            new WeakHashMap(64));
    // Store only one TypeCode per class.
    if ( ! typeCodeForClassMap.containsKey(c))
        typeCodeForClassMap.put(c, tci);
}
 
Example 7
Source File: ExternalPasswordCache.java    From tomcat-vault with Apache License 2.0 5 votes vote down vote up
private ExternalPasswordCache() {
    cache = Collections.synchronizedMap(new HashMap<String, PasswordRecord>());
    try {
        md5Digest = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        // Cannot get MD5 algorithm instance for hashing password commands. Using NULL.
        log.error(sm.getString("externalPasswordCache.cannotGetMD5AlgorithmInstance"));
    }
}
 
Example 8
Source File: TtlMDCAdapter.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
private Map<String, String> duplicateAndInsertNewMap(Map<String, String> oldMap) {
    Map<String, String> newMap = Collections.synchronizedMap(new HashMap<>());
    if (oldMap != null) {
        // we don't want the parent thread modifying oldMap while we are
        // iterating over it
        synchronized (oldMap) {
            newMap.putAll(oldMap);
        }
    }

    copyOnInheritThreadLocal.set(newMap);
    return newMap;
}
 
Example 9
Source File: DnsClient.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public DnsClient(String[] servers, int timeout, int retries)
        throws NamingException {
    this.timeout = timeout;
    this.retries = retries;
    this.servers = new InetAddress[servers.length];
    serverPorts = new int[servers.length];

    for (int i = 0; i < servers.length; i++) {

        // Is optional port given?
        int colon = servers[i].indexOf(':',
                                       servers[i].indexOf(']') + 1);

        serverPorts[i] = (colon < 0)
            ? DEFAULT_PORT
            : Integer.parseInt(servers[i].substring(colon + 1));
        String server = (colon < 0)
            ? servers[i]
            : servers[i].substring(0, colon);
        try {
            this.servers[i] = InetAddress.getByName(server);
        } catch (java.net.UnknownHostException e) {
            NamingException ne = new ConfigurationException(
                    "Unknown DNS server: " + server);
            ne.setRootCause(e);
            throw ne;
        }
    }
    reqs = Collections.synchronizedMap(
        new HashMap<Integer, ResourceRecord>());
    resps = Collections.synchronizedMap(new HashMap<Integer, byte[]>());
}
 
Example 10
Source File: DeepRandomStream.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void open() throws IOException {
  this.tuples = new LinkedList<>();
  this.solrStreams = new ArrayList<>();
  this.eofTuples = Collections.synchronizedMap(new HashMap<>());
  constructStreams();
  openStreams();
}
 
Example 11
Source File: LineNumberInfo.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Constructor.
 * 
 * @param module
 */

public LineNumberInfo( Module module )
{
	this.module = module;
	elementMap = Collections.synchronizedMap( new HashMap<Long, Integer>( ) );
	includeLibStructMap = Collections.synchronizedMap( new HashMap<String, Integer>( ) );
	embeddedImageStructMap = Collections.synchronizedMap( new HashMap<String, Integer>( ) );
	includedCssStyleSheetStructMap = Collections.synchronizedMap( new HashMap<String, Integer>( ) );
	xpathMap = Collections.synchronizedMap( new HashMap<String, Integer>( ) );
	variablesMap = Collections.synchronizedMap( new HashMap<String, Integer>( ) );
}
 
Example 12
Source File: SocketOrChannelConnectionImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public SocketOrChannelConnectionImpl(ORB orb,
                                     Acceptor acceptor,
                                     Socket socket,
                                     boolean useSelectThreadToWait,
                                     boolean useWorkerThread)
{
    this(orb, useSelectThreadToWait, useWorkerThread);

    this.socket = socket;
    socketChannel = socket.getChannel();
    if (socketChannel != null) {
        // REVISIT
        try {
            boolean isBlocking = !useSelectThreadToWait;
            socketChannel.configureBlocking(isBlocking);
        } catch (IOException e) {
            RuntimeException rte = new RuntimeException();
            rte.initCause(e);
            throw rte;
        }
    }
    this.acceptor = acceptor;

    serverRequestMap = Collections.synchronizedMap(new HashMap());
    isServer = true;

    state = ESTABLISHED;
}
 
Example 13
Source File: StaticDatabaseMappingService.java    From waggle-dance with Apache License 2.0 5 votes vote down vote up
public StaticDatabaseMappingService(
    MetaStoreMappingFactory metaStoreMappingFactory,
    List<AbstractMetaStore> initialMetastores) {
  this.metaStoreMappingFactory = metaStoreMappingFactory;
  primaryDatabasesCache = CacheBuilder
      .newBuilder()
      .expireAfterAccess(1, TimeUnit.MINUTES)
      .maximumSize(1)
      .build(new CacheLoader<String, List<String>>() {

        @Override
        public List<String> load(String key) throws Exception {
          if (primaryDatabaseMapping != null) {
            return primaryDatabaseMapping.getClient().get_all_databases();
          } else {
            return Lists.newArrayList();
          }
        }
      });

  mappingsByMetaStoreName = Collections.synchronizedMap(new LinkedHashMap<>());
  mappingsByDatabaseName = Collections.synchronizedMap(new LinkedHashMap<>());
  databaseMappingToDatabaseList = new ConcurrentHashMap<>();
  for (AbstractMetaStore federatedMetaStore : initialMetastores) {
    add(federatedMetaStore);
  }
}
 
Example 14
Source File: java_util_Collections_SynchronizedMap.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected Map<String, String> getObject() {
    Map<String, String> map = Collections.singletonMap("key", "value");
    return Collections.synchronizedMap(map);
}
 
Example 15
Source File: Statistics.java    From marauroa with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor
 */
public Variables() {
	content = Collections.synchronizedMap(new HashMap<String, Long>());
}
 
Example 16
Source File: LimitedAgeDiscCache.java    From letv with Apache License 2.0 4 votes vote down vote up
public LimitedAgeDiscCache(File cacheDir, File reserveCacheDir, FileNameGenerator fileNameGenerator, long maxAge) {
    super(cacheDir, reserveCacheDir, fileNameGenerator);
    this.loadingDates = Collections.synchronizedMap(new HashMap());
    this.maxFileAge = 1000 * maxAge;
}
 
Example 17
Source File: TimeSliceCache.java    From swblocks-decisiontree with Apache License 2.0 4 votes vote down vote up
private TimeSliceCache() {
    this.cache = Collections.synchronizedMap(LruCache.getCache(MAX_CACHE_SIZE, MAX_CACHE_SIZE, 0.75F));
}
 
Example 18
Source File: OuterClassMapper.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public OuterClassMapper(Mapper wrapped, String alias) {
    super(wrapped);
    this.alias = alias;
    innerFields = Collections.synchronizedMap(new HashMap());
    innerFields.put(Object.class.getName(), EMPTY_NAMES);
}
 
Example 19
Source File: XStreamJobRepository.java    From oodt with Apache License 2.0 4 votes vote down vote up
public XStreamJobRepository(File workingDir, int maxHistory) {
	this.workingDir = workingDir;
	this.maxHistory = Math.max(maxHistory == -1 ? Integer.MAX_VALUE : maxHistory, 1);
	this.jobMap = Collections.synchronizedMap(new ConcurrentHashMap<String, String>());
	this.jobPrecedence = new Vector<String>();
}
 
Example 20
Source File: MapScriptObject.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public MapScriptObject(Map map) {
  // make it synchronized
  this.map = Collections.synchronizedMap(map);
}