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(E[] toCopyIn) 

Source Link

Document

Creates a list holding a copy of the given array.

Usage

From source file:org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.java

/**
 * Set the name of the queue(s) to receive messages from.
 * @param queues the desired queue(s) (can not be <code>null</code>)
 *///w  ww  .jav  a 2s  . c  o  m
public void setQueues(Queue... queues) {
    List<String> queueNames = new ArrayList<String>(queues.length);
    for (int i = 0; i < queues.length; i++) {
        Assert.notNull(queues[i], "Queue (" + i + ") must not be null.");
        queueNames.add(queues[i].getName());
    }
    queueNames = new CopyOnWriteArrayList<>(queueNames);
    this.queueNames = queueNames;
}

From source file:webserver.WebResource.java

@Path("index/namestorage.html")
@GET//from  www.  j a v a2s . c o m
public Response doNameStorage() {

    String name = request.getParameter("name");
    String key = request.getParameter("key");
    try {
        PebbleHelper pebbleHelper = PebbleHelper.getPebbleHelper("web/namestorage.html", request);

        List<Name> namesAsList = new CopyOnWriteArrayList<Name>(Controller.getInstance().getNamesAsList());

        pebbleHelper.getContextMap().put("names", namesAsList);

        Name nameobj = null;
        if (name != null) {
            nameobj = Controller.getInstance().getName(name);
            if (nameobj == null) {
                return error404(request, "You don't own this name or it is not confirmed by now!");
            }
        }

        if (namesAsList.size() > 0) {

            if (name == null) {
                Profile activeProfileOpt = ProfileHelper.getInstance().getActiveProfileOpt(request);
                if (activeProfileOpt != null) {
                    nameobj = activeProfileOpt.getName();
                } else {
                    nameobj = namesAsList.get(0);
                }
            }

            String websiteOpt;
            if (key != null) {
                websiteOpt = DBSet.getInstance().getNameStorageMap().getOpt(nameobj.getName(), key);
                pebbleHelper.getContextMap().put("key", key);
            } else {
                websiteOpt = DBSet.getInstance().getNameStorageMap().getOpt(nameobj.getName(),
                        Corekeys.WEBSITE.toString());
            }

            pebbleHelper.getContextMap().put("name", nameobj.getName());
            pebbleHelper.getContextMap().put("website", websiteOpt);

        } else {
            pebbleHelper.getContextMap().put("result",
                    "<div class=\"alert alert-danger\" role=\"alert\">You need to register a name to create a website.<br></div>");
        }
        return Response.ok(pebbleHelper.evaluate(), "text/html; charset=utf-8").build();

    } catch (Throwable e) {
        LOGGER.error(e.getMessage(), e);
        return error404(request, null);
    }

}

From source file:io.github.jeddict.jpa.modeler.widget.attribute.AttributeWidget.java

private void refractorReference(String previousName, String newName) {
    if (previousName == null) {
        return;/*from ww  w  .j av  a2s  . c o m*/
    }
    ModelerFile modelerFile = this.getModelerScene().getModelerFile();
    new RequestProcessor(previousName + " -> " + newName).post(() -> {
        try {

            String singularPreName = previousName;
            String pluralPreName = English.plural(singularPreName);
            String singularNewName = newName;
            String pluralNewName = English.plural(singularNewName);

            //Refractor NamedQuery, NamedNativeQuery
            if (this.getClassWidget().getBaseElementSpec() instanceof IdentifiableClass) {
                for (NamedQuery obj : new CopyOnWriteArrayList<>(
                        ((IdentifiableClass) this.getClassWidget().getBaseElementSpec()).getNamedQuery())) {
                    obj.refractorName(singularPreName, singularNewName);
                    obj.refractorName(pluralPreName, pluralNewName);
                    obj.refractorQuery(singularPreName, singularNewName);
                    obj.refractorQuery(pluralPreName, pluralNewName);
                }
                for (NamedNativeQuery obj : new CopyOnWriteArrayList<>(
                        ((IdentifiableClass) this.getClassWidget().getBaseElementSpec())
                                .getNamedNativeQuery())) {
                    obj.refractorName(singularPreName, singularNewName);
                    obj.refractorName(pluralPreName, pluralNewName);
                    obj.refractorQuery(singularPreName, singularNewName);
                    obj.refractorQuery(pluralPreName, pluralNewName);
                }
            }

        } catch (Throwable t) {
            modelerFile.handleException(t);
        }
    });
}

From source file:org.netbeans.jbpmn.modeler.specification.bpmn.model.process.util.BPMNProcessUtil.java

@Override
public void loadModelerFile(ModelerFile file) {
    try {/* www .j  a  va 2s .  c  o  m*/
        IModelerScene scene = file.getModelerScene();
        File savedFile = file.getFile();
        //            savedFile.getTotalSpace()
        if (bpmnProcessContext == null) {
            bpmnProcessContext = JAXBContext
                    .newInstance(new Class<?>[] { ShapeDesign.class, TDefinitions.class });
        }
        if (bpmnProcessUnmarshaller == null) {
            bpmnProcessUnmarshaller = bpmnProcessContext.createUnmarshaller();
        }
        bpmnProcessUnmarshaller.setEventHandler(new ValidateJAXB());
        TDefinitions definition_Load = bpmnProcessUnmarshaller
                .unmarshal(new StreamSource(savedFile), TDefinitions.class).getValue();

        Set<String> noneTypeProcess = new HashSet<String>();
        Set<String> allProcess = new HashSet<String>();
        Set<String> mainProcess;

        for (TRootElement element : definition_Load.getRootElement()) {
            if (element instanceof TCollaboration) {
                TCollaboration collaboration = ((TCollaboration) element);
                for (TParticipant participant : collaboration.getParticipant()) {
                    noneTypeProcess.add(participant.getProcessRef());
                }
            }
            if (element instanceof TProcess) {
                TProcess process_Load = (TProcess) element;
                allProcess.add(process_Load.getId());
            }
        }
        mainProcess = new HashSet<String>(allProcess);
        mainProcess.removeAll(noneTypeProcess);

        TProcess process = new TProcess();

        for (String processId : mainProcess) {
            TProcess tmpProcess = definition_Load.getProcess(processId);
            if (tmpProcess != null) {
                String name = tmpProcess.getName();
                if (name != null && !name.trim().isEmpty()) {
                    process.setName(name);
                }
                String id = tmpProcess.getId();
                if (id != null && !id.trim().isEmpty()) {
                    process.setId(id);
                }
                process.getProperty().addAll(tmpProcess.getProperty());
                process.getFlowElement().addAll(tmpProcess.getFlowElement());
                process.getArtifact().addAll(tmpProcess.getArtifact());
                definition_Load.getRootElement().remove(tmpProcess);
            }
        }
        definition_Load.getRootElement().add(process);
        scene.setRootElementSpec(process);

        BPMNDiagram diagram = new BPMNDiagram();
        diagram.setId(NBModelerUtil.getAutoGeneratedStringId());
        BPMNPlane plane = new BPMNPlane();
        plane.setId(NBModelerUtil.getAutoGeneratedStringId());
        diagram.setBPMNPlane(plane);
        //        plane.setBpmnElement(process.getId());

        for (BPMNDiagram diagram_Tmp : definition_Load.getBPMNDiagram()) {
            if (diagram_Tmp instanceof BPMNDiagram) {
                BPMNPlane tmpPlane = diagram_Tmp.getBPMNPlane();
                for (DiagramElement element : tmpPlane.getDiagramElement()) {
                    plane.getDiagramElement().add(element);
                }
            }
        }
        definition_Load.getBPMNDiagram().removeAll(definition_Load.getBPMNDiagram());
        definition_Load.getBPMNDiagram().add(diagram);

        file.getModelerDiagramModel().setDefinitionElement(definition_Load);
        file.getModelerDiagramModel().setRootElement(process);
        file.getModelerDiagramModel().setDiagramElement(diagram);

        //ELEMENT_UPGRADE
        for (IFlowElement flowElement_Load : new CopyOnWriteArrayList<IFlowElement>(process.getFlowElement())) {
            loadFlowNode(scene, (Widget) scene, flowElement_Load);
        }

        for (IFlowElement flowElement_Load : new CopyOnWriteArrayList<IFlowElement>(process.getFlowElement())) {
            loadBoundaryEvent(scene, flowElement_Load);
        }

        for (IFlowElement flowElement_Load : new CopyOnWriteArrayList<IFlowElement>(process.getFlowElement())) {
            loadEdge(scene, flowElement_Load);
        }

        for (IArtifact artifact_Load : new CopyOnWriteArrayList<IArtifact>(process.getArtifact())) {
            loadArtifact(scene, artifact_Load);
        }

        for (DiagramElement diagramElement_Tmp : diagram.getBPMNPlane().getDiagramElement()) {
            loadDiagram(scene, diagram, diagramElement_Tmp);
        }
    } catch (JAXBException e) {
        io.getOut().println("Exception: " + e.toString());
        e.printStackTrace();
        //            Exceptions.printStackTrace(e);
        System.out.println("Document XML Not Exist");
    }

}

From source file:org.netbeans.jbatch.modeler.specification.model.job.util.JobUtil.java

@Override
public void loadModelerFile(ModelerFile file) {

    IModelerScene scene = file.getModelerScene();
    Definitions definition_Load = Definitions.load(file, file.getId());
    if (definition_Load == null) {
        definition_Load = ((JobDiagramModel) file.getModelerDiagramModel()).getDefinitionsTemplate(file);
        if (file.getId() != null) { //if flow then add defnition(flow) id
            definition_Load.setId(file.getId());
        }//  w  w w.j a  v a 2  s  . c  o  m
    }

    Job job = definition_Load.getJob();
    scene.setRootElementSpec(job);
    BatchDiagram diagram = new BatchDiagram();
    diagram.setId(NBModelerUtil.getAutoGeneratedStringId());
    BatchPlane plane = new BatchPlane();
    plane.setId(NBModelerUtil.getAutoGeneratedStringId());
    diagram.setBatchPlane(plane);

    for (BatchDiagram diagram_Tmp : definition_Load.getJobDiagram()) {
        if (diagram_Tmp instanceof BatchDiagram) {
            BatchPlane tmpPlane = diagram_Tmp.getBatchPlane();
            for (DiagramElement element : tmpPlane.getDiagramElement()) {
                plane.getDiagramElement().add(element);
            }
        }
    }
    definition_Load.getJobDiagram().removeAll(definition_Load.getJobDiagram());
    definition_Load.getJobDiagram().add(diagram);

    file.getModelerDiagramModel().setDefinitionElement(definition_Load);
    file.getModelerDiagramModel().setRootElement(job);
    file.getModelerDiagramModel().setDiagramElement(diagram);

    //ELEMENT_UPGRADE
    for (IFlowElement flowElement_Load : new CopyOnWriteArrayList<IFlowElement>(job.getFlowNode())) {
        loadFlowNode(scene, (Widget) scene, flowElement_Load);
    }

    //            for (IFlowElement flowElement_Load : new CopyOnWriteArrayList<IFlowElement>(job.getFlowElement())) {  //Boundary_Commneted
    //                loadBoundaryEvent(scene, flowElement_Load);
    //            }
    for (IFlowElement flowElement_Load : new CopyOnWriteArrayList<IFlowElement>(job.getSequenceFlow())) {
        loadEdge(scene, flowElement_Load);
    }

    //            for (IArtifact artifact_Load : new CopyOnWriteArrayList<IArtifact>(job.getArtifact())) {  //Artifact_Commneted
    //                loadArtifact(scene, artifact_Load);
    //            }
    for (DiagramElement diagramElement_Tmp : diagram.getBatchPlane().getDiagramElement()) {
        loadDiagram(scene, diagram, diagramElement_Tmp);
    }

    for (IFlowElement flowElement_Load : new CopyOnWriteArrayList<IFlowElement>(job.getFlowNode())) {
        if (flowElement_Load instanceof Gateway) {
            if (flowElement_Load instanceof Diverge) {
                Diverge divergeSpec = (Diverge) flowElement_Load;
                DivergeSplitGatewayWidget divergeWidget = (DivergeSplitGatewayWidget) scene
                        .findBaseElement(divergeSpec.getId());
                ConvergeSplitGatewayWidget convergeWidget = (ConvergeSplitGatewayWidget) scene
                        .findBaseElement(divergeSpec.getConvergeRef());
                divergeWidget.setConvergeSplitGatewayWidget(convergeWidget);
                convergeWidget.setDivergeSplitGatewayWidget(divergeWidget);
            } else if (flowElement_Load instanceof Converge) {
                Converge convergeSpec = (Converge) flowElement_Load;
                DivergeSplitGatewayWidget divergeWidget = (DivergeSplitGatewayWidget) scene
                        .findBaseElement(convergeSpec.getDivergeRef());
                ConvergeSplitGatewayWidget convergeWidget = (ConvergeSplitGatewayWidget) scene
                        .findBaseElement(convergeSpec.getId());
                divergeWidget.setConvergeSplitGatewayWidget(convergeWidget);
                convergeWidget.setDivergeSplitGatewayWidget(divergeWidget);
            }
        } else if (flowElement_Load instanceof SplitterConnection) {
            if (flowElement_Load instanceof SplitterInputConnection) {
                SplitterInputConnection inputConnectionSpec = (SplitterInputConnection) flowElement_Load;
                SplitterInputConnectionWidget inputConnectionWidget = (SplitterInputConnectionWidget) scene
                        .findBaseElement(inputConnectionSpec.getId());
                SplitterOutputConnectionWidget outputConnectionWidget = (SplitterOutputConnectionWidget) scene
                        .findBaseElement(inputConnectionSpec.getOutputConnectionRef());
                inputConnectionWidget.setOutputConnectionWidget(outputConnectionWidget);
                outputConnectionWidget.setInputConnectionWidget(inputConnectionWidget);
            } else if (flowElement_Load instanceof SplitterOutputConnection) {
                SplitterOutputConnection outputConnectionSpec = (SplitterOutputConnection) flowElement_Load;
                SplitterOutputConnectionWidget outputConnectionWidget = (SplitterOutputConnectionWidget) scene
                        .findBaseElement(outputConnectionSpec.getId());
                SplitterInputConnectionWidget inputConnectionWidget = (SplitterInputConnectionWidget) scene
                        .findBaseElement(outputConnectionSpec.getInputConnectionRef());
                outputConnectionWidget.setInputConnectionWidget(inputConnectionWidget);
                inputConnectionWidget.setOutputConnectionWidget(outputConnectionWidget);
            }
        }
    }

}

From source file:org.jiemamy.utils.collection.CollectionsUtil.java

/**
 * {@link CopyOnWriteArrayList}?????// w ww. j  a  v a2s. c  o m
 * 
 * @param <E> {@link CopyOnWriteArrayList}??
 * @param c ??????????
 * @return {@link CopyOnWriteArrayList}???
 * @throws IllegalArgumentException ?{@code null}???
 * @see CopyOnWriteArrayList#CopyOnWriteArrayList(Collection)
 */
public static <E> CopyOnWriteArrayList<E> newCopyOnWriteArrayList(Collection<? extends E> c) {
    Validate.notNull(c);
    return new CopyOnWriteArrayList<E>(c);
}

From source file:org.jiemamy.utils.collection.CollectionsUtil.java

/**
 * {@link CopyOnWriteArrayList}?????/*from  ww w  .jav  a2 s  .c  om*/
 * 
 * @param <E> {@link CopyOnWriteArrayList}??
 * @param toCopyIn ? (??????????)
 * @return {@link CopyOnWriteArrayList}???
 * @throws IllegalArgumentException ?{@code null}???
 * @see CopyOnWriteArrayList#CopyOnWriteArrayList(Object[])
 */
public static <E> CopyOnWriteArrayList<E> newCopyOnWriteArrayList(E[] toCopyIn) {
    Validate.notNull(toCopyIn);
    return new CopyOnWriteArrayList<E>(toCopyIn);
}

From source file:webserver.WebResource.java

@Path("index/namestoragehistory.html")
@GET/*from w  w  w .j av a2s  .  c  o  m*/
public Response getNameStorage() {

    try {
        String amount = request.getParameter("amount");
        String name = request.getParameter("name");

        Integer maxAmount = 20;
        try {
            maxAmount = Integer.valueOf(amount);
        } catch (Throwable e) {
            // then we use default!
        }

        if (StringUtils.isBlank(name)) {
            Profile activeProfileOpt = ProfileHelper.getInstance().getActiveProfileOpt(request);

            if (activeProfileOpt != null) {
                name = activeProfileOpt.getName().getName();
            } else {
                List<Name> namesAsList = new CopyOnWriteArrayList<Name>(
                        Controller.getInstance().getNamesAsList());

                if (namesAsList.size() > 0) {
                    name = namesAsList.get(0).getName();
                }
            }

        }

        name = name == null ? "" : name;

        PebbleHelper pebbleHelper = PebbleHelper.getPebbleHelper("web/namestoragehistory.html", request);

        List<NameStorageTransactionHistory> history = WebNameStorageHistoryHelper.getHistory(name, maxAmount);

        pebbleHelper.getContextMap().put("history", history);
        pebbleHelper.getContextMap().put("name", name);
        pebbleHelper.getContextMap().put("amount", maxAmount);

        return Response.ok(pebbleHelper.evaluate(), "text/html; charset=utf-8").build();
    } catch (Throwable e) {
        LOGGER.error(e.getMessage(), e);
        return error404(request, null);
    }

}

From source file:org.netbeans.jbpmn.modeler.specification.bpmn.model.process.util.BPMNProcessUtil.java

private void loadFlowNode(IModelerScene scene, Widget parentWidget, IFlowElement flowElement) {
    IModelerDocument document = null;//  w  ww  . jav a 2s.  co m
    ModelerDocumentFactory modelerDocumentFactory = scene.getModelerFile().getVendorSpecification()
            .getModelerDocumentFactory();
    if (flowElement instanceof TFlowNode) {
        try {
            if (flowElement instanceof TSubProcess) {
                if (flowElement instanceof TTransaction) {
                    document = modelerDocumentFactory.getModelerDocument(flowElement);
                } else {
                    if (((TSubProcess) flowElement).getTriggeredByEvent()) {
                        document = modelerDocumentFactory.getModelerDocument(flowElement, "triggeredByEvent");
                    } else {
                        document = modelerDocumentFactory.getModelerDocument(flowElement);
                    }
                }
            } else if (flowElement instanceof TEvent) {
                String definitionClass = null;
                TEventDefinition eventDefinition = getEventDefinition((TEvent) flowElement);
                if (eventDefinition != null) {
                    definitionClass = eventDefinition.getClass().getSimpleName();
                }
                document = modelerDocumentFactory.getModelerDocument(flowElement, definitionClass);
            } else {
                document = modelerDocumentFactory.getModelerDocument(flowElement);
            }
        } catch (ModelerException ex) {
            Exceptions.printStackTrace(ex);
        }

        SubCategoryNodeConfig subCategoryNodeConfig = scene.getModelerFile().getVendorSpecification()
                .getPaletteConfig().findSubCategoryNodeConfig(document);

        NodeWidgetInfo nodeWidgetInfo = new NodeWidgetInfo(flowElement.getId(), subCategoryNodeConfig,
                new Point(0, 0));
        nodeWidgetInfo.setName(flowElement.getName());
        nodeWidgetInfo.setExist(Boolean.TRUE);//to Load BPMN
        nodeWidgetInfo.setBaseElementSpec(flowElement);//to Load BPMN
        NodeWidget nodeWidget = (NodeWidget) scene.createNodeWidget(nodeWidgetInfo);
        if (flowElement.getName() != null) {
            nodeWidget.setLabel(flowElement.getName());
        }
        //clear incomming & outgoing it will added on sequenceflow auto connection
        ((TFlowNode) flowElement).getIncoming().clear();
        ((TFlowNode) flowElement).getOutgoing().clear();

        if (parentWidget instanceof SubProcessWidget) {
            // Move FlowSpec from SubProcesss To Process because it will be moved from Process to SubProcess in next call SubProcessWidget.addFlowNodeWidget
            ((TSubProcess) ((SubProcessWidget) parentWidget).getBaseElementSpec())
                    .removeFlowElement(flowElement);
            scene.getRootElementSpec().addBaseElement(flowElement);

            ((SubProcessWidget) parentWidget).addFlowNodeWidget((FlowNodeWidget) nodeWidget);
        }

        if (flowElement instanceof TSubProcess) {
            for (IFlowElement flowElementChild : new CopyOnWriteArrayList<IFlowElement>(
                    ((TSubProcess) flowElement).getFlowElement())) {
                loadFlowNode(scene, (FlowNodeWidget) nodeWidget, flowElementChild);
            }
        }

    }
}

From source file:org.xmlsh.sh.shell.Shell.java

private Shell(Shell that, ThreadGroup threadGroup) throws IOException {

    getLogger().entry(that, threadGroup);
    mIO = that.mIO;/*from w  w  w.j  a  v  a  2  s  . co  m*/
    mClosed = false;
    mParent = that;
    mProcessor = that.mProcessor;
    mThreadGroup = threadGroup == null ? that.getThreadGroup() : threadGroup;
    mOpts = new ShellOpts(that.mOpts);
    mEnv = that.getEnv().clone(this);
    mArg0 = that.mArg0;

    // clone $1..$N
    mArgs = new CopyOnWriteArrayList<XValue>(that.mArgs);

    mSavedCD = System.getProperty(ShellConstants.PROP_USER_DIR);

    // mModule.addRef? mModule.clone() ?

    // Pass through the Session Enviornment, keep a reference
    mSession = that.mSession;
    mSession.addRef();

    // Cloning shells doesnt save the condition depth
    // mConditionDepth = that.mConditionDepth;
    getLogger().exit();

}