Example usage for java.util Collections synchronizedMap

List of usage examples for java.util Collections synchronizedMap

Introduction

In this page you can find the example usage for java.util Collections synchronizedMap.

Prototype

public static <K, V> Map<K, V> synchronizedMap(Map<K, V> m) 

Source Link

Document

Returns a synchronized (thread-safe) map backed by the specified map.

Usage

From source file:org.apache.zeppelin.interpreter.InterpreterSettingManager.java

public InterpreterSettingManager(ZeppelinConfiguration zeppelinConfiguration,
        DependencyResolver dependencyResolver, InterpreterOption interpreterOption)
        throws IOException, RepositoryException {
    this.zeppelinConfiguration = zeppelinConfiguration;
    this.interpreterDirPath = Paths.get(zeppelinConfiguration.getInterpreterDir());
    logger.debug("InterpreterRootPath: {}", interpreterDirPath);
    this.interpreterBindingPath = Paths.get(zeppelinConfiguration.getInterpreterSettingPath());
    logger.debug("InterpreterBindingPath: {}", interpreterBindingPath);

    this.interpreterSettingsRef = Maps.newConcurrentMap();
    this.interpreterSettings = Maps.newConcurrentMap();
    this.interpreterBindings = Maps.newConcurrentMap();

    this.dependencyResolver = dependencyResolver;
    this.interpreterRepositories = dependencyResolver.getRepos();

    this.defaultOption = interpreterOption;

    this.cleanCl = Collections.synchronizedMap(new HashMap<String, URLClassLoader>());

    String replsConf = zeppelinConfiguration.getString(ConfVars.ZEPPELIN_INTERPRETERS);
    this.interpreterClassList = replsConf.split(",");
    String groupOrder = zeppelinConfiguration.getString(ConfVars.ZEPPELIN_INTERPRETER_GROUP_ORDER);
    this.interpreterGroupOrderList = groupOrder.split(",");

    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setPrettyPrinting();//from   w  ww .j  av  a 2  s  .  c  o  m
    this.gson = gsonBuilder.create();

    init();
}

From source file:op.care.supervisor.PnlHandover.java

private void initPanel() {

    myComparator = new Comparator<NReport>() {
        @Override//from ww  w . j  av a2 s .  c o  m
        public int compare(NReport o1, NReport o2) {
            if (!tbResidentFirst.isSelected()) {
                return o1.getPit().compareTo(o2.getPit());
            } else {
                int comp = o1.getResident().getRID().compareTo(o2.getResident().getRID());
                if (comp == 0) {
                    comp = o1.getPit().compareTo(o2.getPit());
                }
                return comp;
            }
        }
    };

    //        contentmap = Collections.synchronizedMap(new HashMap<String, JPanel>());
    cpMap = Collections.synchronizedMap(new HashMap<String, CollapsiblePane>());
    //        linemapNR = Collections.synchronizedMap(new HashMap<NReport, JPanel>());
    //        linemapHO = Collections.synchronizedMap(new HashMap<Handovers, JPanel>());
    cacheHO = Collections.synchronizedMap(new HashMap<String, ArrayList<Handovers>>());
    cacheNR = Collections.synchronizedMap(new HashMap<String, ArrayList<NReport>>());
    OPDE.getDisplayManager().setMainMessage(SYSTools.xx(internalClassID));
    prepareSearchArea();
}

From source file:net.sf.jasperreports.util.CastorUtil.java

@SuppressWarnings("unchecked")
protected Map<Object, XMLContext> getXmlContextCache(String contextCacheKey) {
    Map<Object, XMLContext> xmlContextCache = (Map<Object, XMLContext>) jasperReportsContext
            .getOwnValue(contextCacheKey);
    if (xmlContextCache == null) {
        //TODO lucianc prevent double cache creation?
        xmlContextCache = Collections.synchronizedMap(new ReferenceMap<Object, XMLContext>(
                ReferenceMap.ReferenceStrength.WEAK, ReferenceMap.ReferenceStrength.SOFT));//using soft values is safer
        jasperReportsContext.setValue(contextCacheKey, xmlContextCache);
    }//  ww w. j a v  a2 s .  c  o m
    return xmlContextCache;
}

From source file:org.apache.abdera.util.AbderaConfiguration.java

/**
 * Registers NamedWriter implementations using the /META-INF/services/org.apache.abdera.writer.NamedWriter file
 *//*from  w w  w . j av a2 s  . c o  m*/
private Map<String, NamedWriter> initNamedWriters() {
    Map<String, NamedWriter> writers = null;
    Iterable<NamedWriter> _writers = Discover.locate(NAMED_WRITER);
    writers = Collections.synchronizedMap(new HashMap<String, NamedWriter>());
    for (NamedWriter writer : _writers) {
        writers.put(writer.getName().toLowerCase(), writer);
    }
    return writers;
}

From source file:nitf.NITFResourceManager.java

private NITFResourceManager() {
    trackedObjects = Collections.synchronizedMap(new LinkedHashMap<Long, TrackedObject>());
}

From source file:com.digitalpebble.storm.crawler.bolt.URLPartitionerBolt.java

@Override
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {

    mode = ConfUtils.getString(stormConf, Constants.PARTITION_MODEParamName, Constants.PARTITION_MODE_HOST);

    // check that the mode is known
    if (!mode.equals(Constants.PARTITION_MODE_IP) && !mode.equals(Constants.PARTITION_MODE_DOMAIN)
            && !mode.equals(Constants.PARTITION_MODE_HOST)) {
        LOG.error("Unknown partition mode : {} - forcing to byHost", mode);
        mode = Constants.PARTITION_MODE_HOST;
    }// w w  w.j a v a 2 s  .  c  o  m

    LOG.info("Using partition mode : {}", mode);

    _collector = collector;
    // Register a "MultiCountMetric" to count different events in this bolt
    // Storm will emit the counts every n seconds to a special bolt via a
    // system stream
    // The data can be accessed by registering a "MetricConsumer" in the
    // topology
    this.eventCounter = context.registerMetric("URLPartitioner", new MultiCountMetric(), 10);

    final int MAX_ENTRIES = 500;
    cache = new LinkedHashMap(MAX_ENTRIES + 1, .75F, true) {
        // This method is called just after a new entry has been added
        @Override
        public boolean removeEldestEntry(Map.Entry eldest) {
            return size() > MAX_ENTRIES;
        }
    };

    // If the cache is to be used by multiple threads,
    // the cache must be wrapped with code to synchronize the methods
    cache = Collections.synchronizedMap(cache);
}

From source file:op.FrmMain.java

public FrmMain() {
    initPhase = true;/*  w  w  w  . j  av  a 2s  .  c  o m*/
    initComponents();

    if (OPDE.isTraining()) {
        pnlMainMessage.setBackground(SYSConst.mediumorchid2.brighter().brighter());
    }

    //        pbTimeout.setToolTipText(SYSTools.xx("opde.mainframe.pbTimeout.tooltip"));
    // for the timeout function
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        @Override
        public void eventDispatched(AWTEvent event) {
            if (OPDE.getLogin() != null) {
                displayManager.touch();
            }
        }
    }, AWTEvent.MOUSE_MOTION_EVENT_MASK);

    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        @Override
        public void eventDispatched(AWTEvent event) {
            if (OPDE.getLogin() != null) {
                displayManager.touch();
            }
        }
    }, AWTEvent.KEY_EVENT_MASK);

    currentVisiblePanel = null;
    currentResident = null;
    lblWait.setText(SYSTools.xx("misc.msg.wait"));
    lblWait.setVisible(false);
    listOfNursingrecords = new ArrayList<CollapsiblePane>();
    btnHelp.setToolTipText(SYSTools.xx("opde.mainframe.btnHelp.tooltip"));

    iconPanels = Collections.synchronizedMap(new HashMap<Resident, JPanel>());

    if (OPDE.isDebug()) {
        setSize(1366, 768);
    } else {
        this.setExtendedState(JFrame.MAXIMIZED_BOTH);
    }

    setTitle(SYSTools.getWindowTitle(""));

    displayManager = new DisplayManager(pbMsg, lblMainMsg, lblSubMsg, pnlIcons, pbTimeout, new Closure() {
        @Override
        public void execute(Object o) {
            OPDE.debug("TIMEOUT");
            logout();
            showLogin();
        }
    });
    displayManager.start();

    printProcessor = new PrintProcessor();
    printProcessor.start();

    // StatusBar Setup
    final LabelStatusBarItem label = new LabelStatusBarItem("Line");
    label.setText(OPDE.getUrl() + " [Build " + OPDE.getAppInfo().getBuildnum() + "]" + " [JVM "
            + System.getProperty("java.version") + "]");
    if (OPDE.isCustomUrl()) {
        label.setForeground(Color.RED);
    }
    label.setFont(new Font("Arial", Font.PLAIN, 14));
    statusBar.add(label, JideBoxLayout.FLEXIBLE);
    labelUSER = new LabelStatusBarItem("Line");
    labelUSER.setText("--");
    labelUSER.setAlignment(JLabel.CENTER);
    labelUSER.setFont(new Font("Arial", Font.PLAIN, 14));
    statusBar.add(labelUSER, JideBoxLayout.FLEXIBLE);
    final TimeStatusBarItem time = new TimeStatusBarItem();
    time.setFont(new Font("Arial", Font.PLAIN, 14));
    time.setUpdateInterval(10000);
    time.setTextFormat(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT));
    time.setAlignment(JLabel.CENTER);
    statusBar.add(time, JideBoxLayout.FLEXIBLE);
    final MemoryStatusBarItem gc = new MemoryStatusBarItem();
    gc.setFont(new Font("Arial", Font.PLAIN, 14));
    statusBar.add(gc, JideBoxLayout.FLEXIBLE);

    btnResetSplitpane.setToolTipText(SYSTools.xx("opde.mainframe.btnSplitReset.tooltip"));

    initPhase = false;

    //        JDialog dlg = new JDialog(this, false);
    //
    //        JPanel pnl = new JPanel();
    //        pnl.setLayout(new VerticalLayout());
    //
    //        for (float f = 0.0f; f <= 1.0; f = f + 0.01f){
    //            JLabel lbl = new JLabel(Float.toString(f));
    //            lbl.setForeground(GUITools.blend(Color.red, Color.WHITE, f));
    //            pnl.add(lbl);
    //        }
    //
    //        dlg.setContentPane(new JScrollPane(pnl));
    //
    //        dlg.pack();
    //        dlg.setVisible(true);

}

From source file:org.xwiki.job.internal.DefaultJobStatusStore.java

@Override
public void initialize() throws InitializationException {
    try {/*from w  w  w  .  j av  a  2 s.co m*/
        this.serializer = new JobStatusSerializer();

        repair();
    } catch (Exception e) {
        this.logger.error("Failed to load jobs", e);
    }

    BasicThreadFactory threadFactory = new BasicThreadFactory.Builder().namingPattern("Job status serializer")
            .daemon(true).priority(Thread.MIN_PRIORITY).build();
    this.executorService = new ThreadPoolExecutor(0, 10, 60L, TimeUnit.SECONDS,
            new SynchronousQueue<Runnable>(), threadFactory);

    this.cache = Collections.synchronizedMap(new Cache(this.configuration.getJobStatusCacheSize()));
}

From source file:fr.immotronic.ubikit.pems.enocean.impl.PairingManagerImpl.java

public PairingManagerImpl(DeviceManager deviceManager,
        /*LicenseManager licenseManager,*/ EventGate eventGateToHigherAbstractionModelLevels,
        ScheduledExecutorService executorService, String pemUID) {
    pairingMode = false;/*from  w  ww . j a va  2  s.c  o  m*/
    this.pemUID = pemUID;
    toPair = Collections.synchronizedMap(new HashMap<String, PairingEntry>());
    executorService.scheduleAtFixedRate(new CleaningThread(), CLEANING_THREAD_SLEEPING_PERIOD,
            CLEANING_THREAD_SLEEPING_PERIOD, TimeUnit.MINUTES);

    this.deviceManager = deviceManager;
    //this.licenseManager = licenseManager;
    this.eventGateToHigherAbstractionModelLevels = eventGateToHigherAbstractionModelLevels;
    eventGateToHigherAbstractionModelLevels.addListener(this);
}

From source file:org.apache.hyracks.control.cc.ClusterControllerService.java

public ClusterControllerService(final CCConfig config, final ICCApplication application) throws Exception {
    this.ccConfig = config;
    this.configManager = ccConfig.getConfigManager();
    if (application == null) {
        throw new IllegalArgumentException("ICCApplication cannot be null");
    }/*from w  ww  . j  a  va2  s  .  c  o m*/
    this.application = application;
    configManager.processConfig();
    File jobLogFolder = new File(ccConfig.getRootDir(), "logs/jobs");
    jobLog = new LogFile(jobLogFolder);

    // WorkQueue is in charge of heartbeat as well as other events.
    workQueue = new WorkQueue("ClusterController", Thread.MAX_PRIORITY);
    this.timer = new Timer(true);
    final ClusterTopology topology = computeClusterTopology(ccConfig);
    ccContext = new ClusterControllerContext(topology);
    sweeper = new DeadNodeSweeper();
    datasetDirectoryService = new DatasetDirectoryService(ccConfig.getResultTTL(),
            ccConfig.getResultSweepThreshold(), preDistributedJobStore);

    deploymentRunMap = new HashMap<>();
    stateDumpRunMap = new HashMap<>();
    threadDumpRunMap = Collections.synchronizedMap(new HashMap<>());

    // Node manager is in charge of cluster membership management.
    nodeManager = new NodeManager(ccConfig, resourceManager);
}