Example usage for java.util.concurrent CopyOnWriteArrayList CopyOnWriteArrayList

List of usage examples for java.util.concurrent CopyOnWriteArrayList CopyOnWriteArrayList

Introduction

In this page you can find the example usage for java.util.concurrent CopyOnWriteArrayList CopyOnWriteArrayList.

Prototype

public CopyOnWriteArrayList() 

Source Link

Document

Creates an empty list.

Usage

From source file:org.mobicents.servlet.restcomm.http.CallsEndpoint.java

@SuppressWarnings("unchecked")
protected Response putCall(final String accountSid, final MultivaluedMap<String, String> data,
        final MediaType responseType) {
    final Sid accountId = new Sid(accountSid);
    secure(daos.getAccountsDao().getAccount(accountSid), "RestComm:Create:Calls");
    try {// w  w  w  .j  a va  2  s  . c  o  m
        validate(data);
        if (normalizePhoneNumbers)
            normalize(data);
    } catch (final RuntimeException exception) {
        return status(BAD_REQUEST).entity(exception.getMessage()).build();
    }
    final String from = data.getFirst("From").trim();
    final String to = data.getFirst("To").trim();
    final String username = data.getFirst("Username");
    final String password = data.getFirst("Password");
    final Integer timeout = getTimeout(data);
    final Timeout expires = new Timeout(Duration.create(60, TimeUnit.SECONDS));
    CreateCall create = null;
    try {
        if (to.contains("@")) {
            create = new CreateCall(from, to, username, password, true, timeout != null ? timeout : 30,
                    CreateCall.Type.SIP, accountId, null);
        } else if (to.startsWith("client")) {
            create = new CreateCall(from, to, username, password, true, timeout != null ? timeout : 30,
                    CreateCall.Type.CLIENT, accountId, null);
        } else {
            create = new CreateCall(from, to, username, password, true, timeout != null ? timeout : 30,
                    CreateCall.Type.PSTN, accountId, null);
        }
        create.setCreateCDR(false);
        if (callManager == null)
            callManager = (ActorRef) context
                    .getAttribute("org.mobicents.servlet.restcomm.telephony.CallManager");
        Future<Object> future = (Future<Object>) ask(callManager, create, expires);
        Object object = Await.result(future, Duration.create(10, TimeUnit.SECONDS));
        Class<?> klass = object.getClass();
        if (CallManagerResponse.class.equals(klass)) {
            final CallManagerResponse<ActorRef> managerResponse = (CallManagerResponse<ActorRef>) object;
            if (managerResponse.succeeded()) {
                List<ActorRef> dialBranches;
                if (managerResponse.get() instanceof List) {
                    dialBranches = (List<ActorRef>) managerResponse.get();
                } else {
                    dialBranches = new CopyOnWriteArrayList<ActorRef>();
                    dialBranches.add(managerResponse.get());
                }
                List<CallDetailRecord> cdrs = new CopyOnWriteArrayList<CallDetailRecord>();
                for (ActorRef call : dialBranches) {
                    future = (Future<Object>) ask(call, new GetCallInfo(), expires);
                    object = Await.result(future, Duration.create(10, TimeUnit.SECONDS));
                    klass = object.getClass();
                    if (CallResponse.class.equals(klass)) {
                        final CallResponse<CallInfo> callResponse = (CallResponse<CallInfo>) object;
                        if (callResponse.succeeded()) {
                            final CallInfo callInfo = callResponse.get();
                            // Execute the call script.
                            final String version = getApiVersion(data);
                            final URI url = getUrl("Url", data);
                            final String method = getMethod("Method", data);
                            final URI fallbackUrl = getUrl("FallbackUrl", data);
                            final String fallbackMethod = getMethod("FallbackMethod", data);
                            final URI callback = getUrl("StatusCallback", data);
                            final String callbackMethod = getMethod("StatusCallbackMethod", data);
                            final ExecuteCallScript execute = new ExecuteCallScript(call, accountId, version,
                                    url, method, fallbackUrl, fallbackMethod, callback, callbackMethod);
                            callManager.tell(execute, null);
                            cdrs.add(daos.getCallDetailRecordsDao().getCallDetailRecord(callInfo.sid()));
                        }
                    }
                }
                if (APPLICATION_XML_TYPE == responseType) {
                    if (cdrs.size() == 1) {
                        return ok(xstream.toXML(cdrs.get(0)), APPLICATION_XML).build();
                    } else {
                        final RestCommResponse response = new RestCommResponse(new CallDetailRecordList(cdrs));
                        return ok(xstream.toXML(response), APPLICATION_XML).build();
                    }
                } else if (APPLICATION_JSON_TYPE == responseType) {
                    if (cdrs.size() == 1) {
                        return ok(gson.toJson(cdrs.get(0)), APPLICATION_JSON).build();
                    } else {
                        return ok(gson.toJson(cdrs), APPLICATION_JSON).build();
                    }
                } else {
                    return null;
                }
                //                    if (APPLICATION_JSON_TYPE == responseType) {
                //                        return ok(gson.toJson(cdrs), APPLICATION_JSON).build();
                //                    } else if (APPLICATION_XML_TYPE == responseType) {
                //                        return ok(xstream.toXML(new RestCommResponse(cdrs)), APPLICATION_XML).build();
                //                    } else {
                //                        return null;
                //                    }
            } else {
                return status(INTERNAL_SERVER_ERROR)
                        .entity(managerResponse.cause() + " : " + managerResponse.error()).build();
            }
        }
        return status(INTERNAL_SERVER_ERROR).build();
    } catch (final Exception exception) {
        return status(INTERNAL_SERVER_ERROR).entity(exception.getMessage()).build();
    }
}

From source file:org.wso2.carbon.event.receiver.core.internal.CarbonEventReceiverService.java

public void addEventReceiverConfigurationFile(EventReceiverConfigurationFile eventReceiverConfigurationFile,
        int tenantId) {
    List<EventReceiverConfigurationFile> eventReceiverConfigurationFiles = tenantSpecificEventReceiverConfigurationFileMap
            .get(tenantId);/*from ww w  . java  2 s.co  m*/
    if (eventReceiverConfigurationFiles == null) {
        eventReceiverConfigurationFiles = new CopyOnWriteArrayList<>();
    } else {
        for (EventReceiverConfigurationFile anEventReceiverConfigurationFileList : eventReceiverConfigurationFiles) {
            if (anEventReceiverConfigurationFileList.getFileName()
                    .equals(eventReceiverConfigurationFile.getFileName())) {
                return;
            }
        }
    }
    eventReceiverConfigurationFiles.add(eventReceiverConfigurationFile);
    tenantSpecificEventReceiverConfigurationFileMap.put(tenantId, eventReceiverConfigurationFiles);
}

From source file:org.wso2.carbon.device.mgt.output.adapter.websocket.WebsocketEventAdapter.java

/**
 * Fetches all valid web-socket sessions from the entire pool of subscribed sessions. The validity is checked
 * against any queryString provided when subscribing to the web-socket endpoint.
 *
 * @param event the current event received and that which needs to be published to subscribed sessions.
 * @return a list of all validated web-socket sessions against the queryString values.
 *///from   ww w  .  j a  v a2 s.  c om
private CopyOnWriteArrayList<WebSocketSessionRequest> getValidSessions(Object event) {
    CopyOnWriteArrayList<WebSocketSessionRequest> validSessions = new CopyOnWriteArrayList<>();
    WebsocketOutputCallbackControllerServiceImpl websocketOutputCallbackControllerServiceImpl = WebsocketEventAdaptorServiceDataHolder
            .getUIOutputCallbackRegisterServiceImpl();
    // get all subscribed web-socket sessions.
    CopyOnWriteArrayList<WebSocketSessionRequest> webSocketSessionUtils = websocketOutputCallbackControllerServiceImpl
            .getSessions(tenantId, streamId);
    if (webSocketSessionUtils != null) {
        for (WebSocketSessionRequest webSocketSessionUtil : webSocketSessionUtils) {
            boolean isValidSession;
            if (event instanceof Event) {
                isValidSession = validateEventAgainstSessionFilters((Event) event, webSocketSessionUtil);
            } else {
                isValidSession = validateJsonMessageAgainstEventFilters(event.toString(), webSocketSessionUtil);
            }
            if (isValidSession) {
                validSessions.add(webSocketSessionUtil);
            }
        }
    }
    return validSessions;
}

From source file:org.github.gitswarm.GitSwarm.java

/**
 * TODO This could be made to look a lot better.
 *///www . j a v a  2s. c  o m
private void drawPopular() {
    CopyOnWriteArrayList<FileNode> al = new CopyOnWriteArrayList<>();
    noStroke();
    textFont(font);
    textAlign(RIGHT, TOP);
    fill(fontColor, 200);
    text("Popular Nodes (touches):", width - 120, 0);
    for (FileNode fn : nodes.values()) {
        if (fn.qualifies()) {
            // Insertion Sort
            if (al.size() > 0) {
                int j = 0;
                for (; j < al.size(); j++) {
                    if (fn.compareTo(al.get(j)) > 0) {
                        break;
                    }
                }
                al.add(j, fn);
            } else {
                al.add(fn);
            }
        }
    }

    int i = 1;
    ListIterator<FileNode> it = al.listIterator();
    while (it.hasNext()) {
        FileNode n = it.next();
        // Limit to the top 10.
        if (i <= 10) {
            text(n.getName() + "  (" + n.getTouches() + ")", width - 100, 10 * i++);
        } else if (i > 10) {
            break;
        }
    }
}

From source file:com.chiorichan.site.Site.java

public List<String> getMetatags() {
    if (metatags == null)
        return new CopyOnWriteArrayList<String>();

    return metatags;
}

From source file:org.fcrepo.integration.kernel.modeshape.observer.SimpleObserverIT.java

@Before
public void acquireConnections() {
    eventBusMessageCount = 0;
    events = new CopyOnWriteArrayList<>();
    eventBus.register(this);
}

From source file:org.wso2.carbon.event.publisher.core.internal.CarbonEventPublisherService.java

public void addEventPublisherConfigurationFile(EventPublisherConfigurationFile eventPublisherConfigurationFile,
        int tenantId) {

    List<EventPublisherConfigurationFile> eventPublisherConfigurationFileList = tenantSpecificEventPublisherConfigurationFileMap
            .get(tenantId);//from  ww  w.j av  a2s .  co  m

    if (eventPublisherConfigurationFileList == null) {
        eventPublisherConfigurationFileList = new CopyOnWriteArrayList<>();
    } else {
        for (EventPublisherConfigurationFile anEventPublisherConfigurationFileList : eventPublisherConfigurationFileList) {
            if (anEventPublisherConfigurationFileList.getFileName()
                    .equals(eventPublisherConfigurationFile.getFileName())) {
                return;
            }
        }
    }
    eventPublisherConfigurationFileList.add(eventPublisherConfigurationFile);
    tenantSpecificEventPublisherConfigurationFileMap.put(tenantId, eventPublisherConfigurationFileList);
}

From source file:net.java.html.charts.ChartsTest.java

/**
 *
 * @throws Exception/*  w  w w.  j a v a  2 s  .  c  om*/
 */
@Test
public void restyleTest() throws Exception {
    run(() -> {
        List<Number> x = new CopyOnWriteArrayList<>();
        for (int i = 0; i < 10; i++) {
            x.add(i);
        }
        List<Number> y = new CopyOnWriteArrayList<>();
        for (int i = 0; i < 10; i++) {
            y.add(i);
        }
        CartesianTrace trace = new CartesianTrace(x, y);
        Scatter<CartesianTrace> sctr = Scatter.<CartesianTrace>builder().trace(trace).build();
        net.java.html.plotlyjs.PlotlyData<Scatter<CartesianTrace>> data = new PlotlyData<>(sctr);
        chart = Plotly.newPlot("chart", data, new Layout.Builder().title("chart").build());
        ScatterMarker restyle = ScatterMarker.builder().opacity(0.5).build();
        Scatter<CartesianTrace> replacement = Scatter.<CartesianTrace>builder().trace(trace).marker(restyle)
                .build();
        chart.restyle(replacement, 0);
        JSObject plotdata = (JSObject) chart.getPlot();
        double newOpacity = (Double) plotdata.eval("this.data[0].marker.opacity");
        assertEquals(newOpacity, 0.5); //make sure we have the right restyle data

        return null;
    });
}

From source file:eu.tango.energymodeller.datasourceclient.WattsUpMeterDataSourceAdaptor.java

@Override
public synchronized double getCpuUtilisation(Host host, int lastNSeconds) {
    double count = 0.0;
    double sumOfUtil = 0.0;
    GregorianCalendar cal = new GregorianCalendar();
    long now = TimeUnit.MILLISECONDS.toSeconds(cal.getTimeInMillis());
    long nowMinustime = now - lastNSeconds;
    CopyOnWriteArrayList<CPUUtilisation> list = new CopyOnWriteArrayList<>();
    list.addAll(cpuMeasure);/* w  ww  .  j a v a 2  s . c  o  m*/
    for (Iterator<CPUUtilisation> it = list.iterator(); it.hasNext();) {
        CPUUtilisation util = it.next();
        if (util.isOlderThan(nowMinustime)) {
            list.remove(util);
            cpuMeasure.remove(util);
        } else {
            sumOfUtil = sumOfUtil + util.getCpuBusy();
            count = count + 1;
        }
    }
    if (count == 0) {
        return 0.0;
    }
    return sumOfUtil / count;
}