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

The following examples show how to use java.util.Collections#synchronizedMap() . These examples are extracted from open source projects. 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
/**
 *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
/**
 * 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 Project: j2objc   File: Collections2Test.java    License: 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
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 5
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 6
Source Project: birt   File: LineNumberInfo.java    License: 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 7
Source Project: lucene-solr   File: DeepRandomStream.java    License: 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 8
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 9
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 10
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 11
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 12
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 13
Source Project: hop   File: RemotePipelineEngine.java    License: 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 14
Source Project: oodt   File: XStreamJobRepository.java    License: 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 15
public OuterClassMapper(Mapper wrapped, String alias) {
    super(wrapped);
    this.alias = alias;
    innerFields = Collections.synchronizedMap(new HashMap());
    innerFields.put(Object.class.getName(), EMPTY_NAMES);
}
 
Example 16
private TimeSliceCache() {
    this.cache = Collections.synchronizedMap(LruCache.getCache(MAX_CACHE_SIZE, MAX_CACHE_SIZE, 0.75F));
}
 
Example 17
Source Project: letv   File: LimitedAgeDiscCache.java    License: 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 18
protected Map<String, String> getObject() {
    Map<String, String> map = Collections.singletonMap("key", "value");
    return Collections.synchronizedMap(map);
}
 
Example 19
/**
 * Constructor
 */
public Variables() {
	content = Collections.synchronizedMap(new HashMap<String, Long>());
}
 
Example 20
public MapScriptObject(Map map) {
  // make it synchronized
  this.map = Collections.synchronizedMap(map);
}