Example usage for java.util Collections synchronizedList

List of usage examples for java.util Collections synchronizedList

Introduction

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

Prototype

public static <T> List<T> synchronizedList(List<T> list) 

Source Link

Document

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

Usage

From source file:com.nextep.designer.sqlclient.ui.model.impl.SQLQuery.java

public SQLQuery(Connection connection, String sql) {
    this.sqlQuery = sql;
    result = new SQLResult(this);
    this.connection = connection;
    listeners = Collections.synchronizedList(new ArrayList<ISQLQueryListener>());
    isDisposed = false;//from w  w w . j  a v a  2s.  com
}

From source file:org.apache.hadoop.util.PluginDispatcher.java

PluginDispatcher(Collection<T> plugins, Executor executor) {
    this.plugins = Collections.synchronizedList(new ArrayList<T>(plugins));
    this.executor = executor;
}

From source file:org.jcf.MultiUserChatImpl.java

/**
 * default ctor. use connect to connect to the jabber server
 * @param jabberServer chatserver name//from   www .  j a  v  a2 s .  c om
 * @param userName username in chatserver to connect
 * @param passwd password on chatserver
 */
MultiUserChatImpl(JCFConnection jCFConnection) {
    Assert.notNull(jCFConnection);

    this.jCFConnection = jCFConnection;
    messageListener = Collections.synchronizedList(new ArrayList<JCFMessageListener>());
    invitationRejectionListener = Collections.synchronizedList(new ArrayList<MUCInvitationRejectionListener>());
    threadList = Collections.synchronizedList(new ArrayList<JCFMessageThread>());
}

From source file:org.jboss.dashboard.commons.events.Publisher.java

/**
 * Register a subscriber interested in a single event.
 * @param eventId The event interested in.
 * <p>NOTE: <code>EVENT_ALL=0</code> is a reserved identifier.
 *//*from www.  j a v a  2s.  co m*/
public synchronized void subscribe(Subscriber subscriber, int eventId) {
    if (subscriber == null)
        return;

    // Discard duplicates.
    unsubscribe(subscriber, eventId);

    // Avoid subscribers to be "leaked" by the process manager.
    // Solve the -lapsed listener- problem.
    List eventSubscribers = (List) subscribers.get(new Integer(eventId));
    if (eventSubscribers == null) {
        eventSubscribers = Collections.synchronizedList(new ArrayList());
        subscribers.put(new Integer(eventId), eventSubscribers);
    }
    eventSubscribers.add(new WeakReference(subscriber));
}

From source file:io.cloudslang.samples.StandAloneTest.java

@Before
public void init() {
    eventQueue = Collections.synchronizedList(new ArrayList<ScoreEvent>());
}

From source file:org.opencms.xml.containerpage.CmsADESessionCache.java

/**
 * Initializes the session cache.<p>
 * //from   ww  w .ja  va  2 s. c om
 * @param cms the cms context
 */
public CmsADESessionCache(CmsObject cms) {

    // container element cache
    Map<String, CmsContainerElementBean> lruMapCntElem = new HashMap<String, CmsContainerElementBean>();
    m_containerElements = Collections.synchronizedMap(lruMapCntElem);

    // ADE recent lists
    int maxElems = 10;
    maxElems = OpenCms.getADEManager().getRecentListMaxSize(cms.getRequestContext().getCurrentUser());
    List<CmsContainerElementBean> adeRecentList = CmsCollectionsGenericWrapper
            .list(new NodeCachingLinkedList(maxElems));
    m_recentLists = Collections.synchronizedList(adeRecentList);
}

From source file:org.apache.jackrabbit.core.integration.InterruptedQueryTest.java

@Test
public void testQuery() throws Exception {
    if (Constants.WINDOWS) {
        return;/*from w  w w  .ja v  a 2s.c  om*/
    }
    for (int i = 0; i < 100; i++) {
        session.getRootNode().addNode("node" + i, "nt:unstructured");
    }
    session.save();
    final QueryManager qm = session.getWorkspace().getQueryManager();
    final AtomicBoolean stop = new AtomicBoolean(false);
    final List<Exception> exceptions = Collections.synchronizedList(new ArrayList<Exception>());
    Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
            while (!stop.get() && exceptions.isEmpty()) {
                try {
                    // execute query
                    String stmt = "//*[@jcr:primaryType='nt:unstructured']";
                    qm.createQuery(stmt, Query.XPATH).execute();
                } catch (RepositoryException e) {
                    if (Constants.SUN_OS) {
                        // on Solaris it's OK when the root cause
                        // of the exception is an InterruptedIOException
                        // the underlying file is not closed
                        Throwable t = e;
                        while (t.getCause() != null) {
                            t = t.getCause();
                        }
                        if (!(t instanceof InterruptedIOException)) {
                            exceptions.add(e);
                        }
                    } else {
                        exceptions.add(e);
                    }
                }
            }
        }
    });
    t.start();
    for (int i = 0; i < 200 && t.isAlive(); i++) {
        t.interrupt();
        Thread.sleep((long) (100.0 * Math.random()));
    }
    stop.set(true);
    t.join();
    if (!exceptions.isEmpty()) {
        throw exceptions.get(0);
    }
}

From source file:org.pentaho.di.www.Carte.java

public Carte(final SlaveServerConfig config, Boolean joinOverride) throws Exception {
    this.config = config;

    allOK = true;/*from w w w .java 2s  .com*/

    CarteSingleton.setSlaveServerConfig(config);
    LogChannelInterface log = CarteSingleton.getInstance().getLog();

    final TransformationMap transformationMap = CarteSingleton.getInstance().getTransformationMap();
    transformationMap.setSlaveServerConfig(config);
    final JobMap jobMap = CarteSingleton.getInstance().getJobMap();
    jobMap.setSlaveServerConfig(config);
    List<SlaveServerDetection> detections = Collections.synchronizedList(new ArrayList<SlaveServerDetection>());
    SocketRepository socketRepository = CarteSingleton.getInstance().getSocketRepository();

    SlaveServer slaveServer = config.getSlaveServer();

    String hostname = slaveServer.getHostname();
    int port = WebServer.PORT;
    if (!Const.isEmpty(slaveServer.getPort())) {
        try {
            port = Integer.parseInt(slaveServer.getPort());
        } catch (Exception e) {
            log.logError(BaseMessages.getString(PKG, "Carte.Error.CanNotPartPort", slaveServer.getHostname(),
                    "" + port), e);
            allOK = false;
        }
    }

    // TODO: see if we need to keep doing this on a periodic basis.
    // The master might be dead or not alive yet at the time we send this message.
    // Repeating the registration over and over every few minutes might harden this sort of problems.
    //
    if (config.isReportingToMasters()) {
        final SlaveServer client = new SlaveServer("Dynamic slave [" + hostname + ":" + port + "]", hostname,
                "" + port, slaveServer.getUsername(), slaveServer.getPassword());
        for (final SlaveServer master : config.getMasters()) {
            // Here we use the username/password specified in the slave server section of the configuration.
            // This doesn't have to be the same pair as the one used on the master!
            //
            try {
                SlaveServerDetection slaveServerDetection = new SlaveServerDetection(client);
                master.sendXML(slaveServerDetection.getXML(), RegisterSlaveServlet.CONTEXT_PATH + "/");
                log.logBasic("Registered this slave server to master slave server [" + master.toString()
                        + "] on address [" + master.getServerAndPort() + "]");
            } catch (Exception e) {
                log.logError("Unable to register to master slave server [" + master.toString()
                        + "] on address [" + master.getServerAndPort() + "]");
                allOK = false;
            }
        }
    }

    // If we need to time out finished or idle objects, we should create a timer in the background to clean
    // this is done automatically now
    // CarteSingleton.installPurgeTimer(config, log, transformationMap, jobMap);

    if (allOK) {
        boolean shouldJoin = config.isJoining();
        if (joinOverride != null) {
            shouldJoin = joinOverride;
        }
        this.webServer = new WebServer(log, transformationMap, jobMap, socketRepository, detections, hostname,
                port, shouldJoin, config.getPasswordFile());
    }
}

From source file:org.rifidi.designer.services.core.events.EventsServiceImpl.java

private void init() {
    inited = true;//  w w w.  j  av  a  2s .co  m
    eventStack = new Stack<WorldEvent>();
    eventTypes = Collections.synchronizedList(new ArrayList<Class>());
    Activator.display.asyncExec(new Runnable() {

        /*
         * (non-Javadoc)
         * 
         * @see java.lang.Runnable#run()
         */
        @Override
        public void run() {
            MessageConsole fMessageConsole = new MessageConsole("TagMessages", null);
            ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { fMessageConsole });
            msgConsoleStreamRed = fMessageConsole.newMessageStream();
            msgConsoleStreamRed.setColor(Activator.display.getSystemColor(SWT.COLOR_RED));
            msgConsoleStreamBlack = fMessageConsole.newMessageStream();
            msgConsoleStreamBlack.setColor(Activator.display.getSystemColor(SWT.COLOR_BLACK));
            msgConsoleStreamGreen = fMessageConsole.newMessageStream();
            msgConsoleStreamGreen.setColor(Activator.display.getSystemColor(SWT.COLOR_GREEN));
            recordedEvents = new HashMap<Long, WorldEvent>();
            thread = new ProcessingThread("eventProcessingThread", eventStack, eventTypes, msgConsoleStreamRed,
                    msgConsoleStreamBlack, msgConsoleStreamGreen);
            thread.start();
        }

    });

}

From source file:kenh.xscript.Environment.java

/**
 * Initial method/* ww  w  .  java 2  s.  c om*/
 */
private void initial() {

    // 
    Map<String, Element> methods = Collections.synchronizedMap(new LinkedHashMap());
    this.setVariable(KEY_METHODS, methods);

    // public
    List<String> publics = Collections.synchronizedList(new LinkedList());
    this.setVariable(KEY_PUBLIC, publics);

    // 
    List<String> constant = Collections.synchronizedList(new LinkedList());
    this.setVariable(KEY_CONSTANT, constant);

    constant.add(KEY_METHODS);
    constant.add(KEY_PUBLIC);
    constant.add(KEY_CONSTANT);

    publics.add(KEY_METHODS);
    publics.add(KEY_PUBLIC);
    publics.add(KEY_CONSTANT);

}