Search in sources :

Example 51 with Collections

use of java.util.Collections in project spring-framework by spring-projects.

the class TomcatRequestUpgradeStrategy method upgrade.

@Override
public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler, Optional<String> subProtocol) {
    ServerHttpRequest request = exchange.getRequest();
    ServerHttpResponse response = exchange.getResponse();
    HttpServletRequest servletRequest = getHttpServletRequest(request);
    HttpServletResponse servletResponse = getHttpServletResponse(response);
    Endpoint endpoint = new StandardWebSocketHandlerAdapter(handler, session -> {
        HandshakeInfo info = getHandshakeInfo(exchange, subProtocol);
        DataBufferFactory factory = response.bufferFactory();
        return new StandardWebSocketSession(session, info, factory);
    });
    String requestURI = servletRequest.getRequestURI();
    DefaultServerEndpointConfig config = new DefaultServerEndpointConfig(requestURI, endpoint);
    config.setSubprotocols(subProtocol.map(Collections::singletonList).orElse(Collections.emptyList()));
    try {
        WsServerContainer container = getContainer(servletRequest);
        container.doUpgrade(servletRequest, servletResponse, config, Collections.emptyMap());
    } catch (ServletException | IOException ex) {
        return Mono.error(ex);
    }
    return Mono.empty();
}
Also used : WsServerContainer(org.apache.tomcat.websocket.server.WsServerContainer) StandardWebSocketHandlerAdapter(org.springframework.web.reactive.socket.adapter.StandardWebSocketHandlerAdapter) ServletServerHttpRequest(org.springframework.http.server.reactive.ServletServerHttpRequest) ServerHttpRequest(org.springframework.http.server.reactive.ServerHttpRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) ServerHttpResponse(org.springframework.http.server.reactive.ServerHttpResponse) ServletServerHttpResponse(org.springframework.http.server.reactive.ServletServerHttpResponse) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) Endpoint(javax.websocket.Endpoint) StandardWebSocketSession(org.springframework.web.reactive.socket.adapter.StandardWebSocketSession) Collections(java.util.Collections) DataBufferFactory(org.springframework.core.io.buffer.DataBufferFactory) HandshakeInfo(org.springframework.web.reactive.socket.HandshakeInfo)

Example 52 with Collections

use of java.util.Collections in project L42 by ElvisResearchGroup.

the class Translator method useFrom.

//this should take a class, strip out nested and 'from' it so that it is as at top level
static ClassB useFrom(ClassB ct, Path p) {
    ArrayList<Member> ms = new ArrayList<Member>();
    for (Member m : ct.getMs()) {
        m.match(nc -> null, mi -> {
            throw Assertions.codeNotReachable();
        }, mt -> ms.add(From.from(mt, p)));
    }
    //for(PathMwt pmwt:ct.getStage().getInherited()){
    for (PathMwt pmwt : Collections.<PathMwt>emptyList()) {
        if (Functions.getIfInDom(ms, pmwt.getMwt().getMs()).isPresent()) {
            continue;
        }
        ms.add(From.from(pmwt.getMwt(), p));
    }
    List<Path> sup = tools.Map.of(ti -> (Path) From.fromP(ti.getPath(), p), ct.getSupertypes());
    //tools.Map.of(pi->(Path)From.fromP(pi,p),ct.getStage().getInheritedPaths());
    List<Path> supAll = sup;
    ClassB res = ct.withMs(ms).withSupertypes(tools.Map.of(pi -> pi.toImmNT(), sup));
    return res;
}
Also used : Path(ast.Ast.Path) From(coreVisitors.From) Stage(ast.Ast.Stage) Arrays(java.util.Arrays) Program(programReduction.Program) Ast(ast.Ast) Configuration(facade.Configuration) Type(ast.Ast.Type) HashMap(java.util.HashMap) Assertions(tools.Assertions) ArrayList(java.util.ArrayList) CompilationError(platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.CompilationError) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) ClassB(ast.ExpCore.ClassB) InterfaceHeader(ast.Ast.InterfaceHeader) Map(java.util.Map) Facade(reduction.Facade) PathMwt(ast.Util.PathMwt) MapClassLoader(platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.MapClassLoader) Method(java.lang.reflect.Method) IsCompiled(coreVisitors.IsCompiled) NestedClass(ast.ExpCore.ClassB.NestedClass) Files(java.nio.file.Files) Path(ast.Ast.Path) Doc(ast.Ast.Doc) Phase(ast.ExpCore.ClassB.Phase) IOException(java.io.IOException) ExpCore(ast.ExpCore) Member(ast.ExpCore.ClassB.Member) Functions(auxiliaryGrammar.Functions) InvocationTargetException(java.lang.reflect.InvocationTargetException) Util(ast.Util) Consumer(java.util.function.Consumer) List(java.util.List) EmptyProgram(programReduction.Program.EmptyProgram) Paths(java.nio.file.Paths) Optional(java.util.Optional) SourceFile(platformSpecific.inMemoryCompiler.InMemoryJavaCompiler.SourceFile) Timer(profiling.Timer) InMemoryJavaCompiler(platformSpecific.inMemoryCompiler.InMemoryJavaCompiler) Collections(java.util.Collections) L42(facade.L42) ArrayList(java.util.ArrayList) Member(ast.ExpCore.ClassB.Member) PathMwt(ast.Util.PathMwt) ClassB(ast.ExpCore.ClassB)

Example 53 with Collections

use of java.util.Collections in project wildfly by wildfly.

the class ChannelCommandDispatcher method submitOnCluster.

@Override
public <R> Map<Node, Future<R>> submitOnCluster(Command<R, ? super C> command, Node... excludedNodes) throws CommandDispatcherException {
    Map<Node, Future<R>> results = new ConcurrentHashMap<>();
    FutureListener<RspList<R>> listener = future -> {
        try {
            future.get().keySet().stream().map(address -> this.factory.createNode(address)).forEach(node -> results.remove(node));
        } catch (CancellationException e) {
        } catch (ExecutionException e) {
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    };
    Message message = this.createMessage(command);
    RequestOptions options = this.createRequestOptions(excludedNodes);
    try {
        Future<? extends Map<Address, Rsp<R>>> futureResponses = this.dispatcher.castMessageWithFuture(null, message, options, listener);
        Set<Node> excluded = (excludedNodes != null) ? new HashSet<>(Arrays.asList(excludedNodes)) : Collections.<Node>emptySet();
        for (Address address : this.dispatcher.getChannel().getView().getMembers()) {
            Node node = this.factory.createNode(address);
            if (!excluded.contains(node)) {
                Future<R> future = new Future<R>() {

                    @Override
                    public boolean cancel(boolean mayInterruptIfRunning) {
                        return futureResponses.cancel(mayInterruptIfRunning);
                    }

                    @Override
                    public R get() throws InterruptedException, ExecutionException {
                        Map<Address, Rsp<R>> responses = futureResponses.get();
                        Rsp<R> response = responses.get(address);
                        if (response == null) {
                            throw new CancellationException();
                        }
                        return createCommandResponse(response).get();
                    }

                    @Override
                    public R get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
                        Map<Address, Rsp<R>> responses = futureResponses.get(timeout, unit);
                        Rsp<R> response = responses.get(address);
                        if (response == null) {
                            throw new CancellationException();
                        }
                        return createCommandResponse(response).get();
                    }

                    @Override
                    public boolean isCancelled() {
                        return futureResponses.isCancelled();
                    }

                    @Override
                    public boolean isDone() {
                        return futureResponses.isDone();
                    }
                };
                results.put(node, future);
            }
        }
        return results;
    } catch (Exception e) {
        throw new CommandDispatcherException(e);
    }
}
Also used : Arrays(java.util.Arrays) Rsp(org.jgroups.util.Rsp) TimeoutException(java.util.concurrent.TimeoutException) HashMap(java.util.HashMap) FutureListener(org.jgroups.util.FutureListener) HashSet(java.util.HashSet) CommandDispatcher(org.wildfly.clustering.dispatcher.CommandDispatcher) Command(org.wildfly.clustering.dispatcher.Command) Future(java.util.concurrent.Future) RspFilter(org.jgroups.blocks.RspFilter) RequestOptions(org.jgroups.blocks.RequestOptions) Map(java.util.Map) RspList(org.jgroups.util.RspList) Address(org.jgroups.Address) NodeFactory(org.wildfly.clustering.group.NodeFactory) CancellationException(java.util.concurrent.CancellationException) ResponseMode(org.jgroups.blocks.ResponseMode) CommandResponse(org.wildfly.clustering.dispatcher.CommandResponse) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Addressable(org.wildfly.clustering.server.Addressable) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Message(org.jgroups.Message) Node(org.wildfly.clustering.group.Node) CommandDispatcherException(org.wildfly.clustering.dispatcher.CommandDispatcherException) Collections(java.util.Collections) MessageDispatcher(org.jgroups.blocks.MessageDispatcher) Message(org.jgroups.Message) Address(org.jgroups.Address) RequestOptions(org.jgroups.blocks.RequestOptions) CommandDispatcherException(org.wildfly.clustering.dispatcher.CommandDispatcherException) Node(org.wildfly.clustering.group.Node) RspList(org.jgroups.util.RspList) Rsp(org.jgroups.util.Rsp) TimeoutException(java.util.concurrent.TimeoutException) CancellationException(java.util.concurrent.CancellationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) CommandDispatcherException(org.wildfly.clustering.dispatcher.CommandDispatcherException) CancellationException(java.util.concurrent.CancellationException) Future(java.util.concurrent.Future) TimeUnit(java.util.concurrent.TimeUnit) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ExecutionException(java.util.concurrent.ExecutionException)

Example 54 with Collections

use of java.util.Collections in project coffeenet-starter by coffeenet.

the class CoffeeNetWebServiceImpl method get.

@Override
public CoffeeNetWeb get() {
    CoffeeNetWebUser coffeeNetWebUser = coffeeNetWebExtractor.extractUser().orElse(null);
    Map<String, List<CoffeeNetApp>> apps = coffeeNetWebExtractor.extractApps().orElseGet(Collections::emptyMap);
    String logoutPath = coffeeNetWebExtractor.extractLogoutPath();
    List<CoffeeNetApp> profileApps = apps.get("profile");
    CoffeeNetApp profileApp = null;
    if (profileApps != null && !profileApps.isEmpty()) {
        profileApp = profileApps.get(0);
    }
    List<CoffeeNetApp> coffeeNetApps = apps.get("apps");
    return new CoffeeNetWeb(coffeeNetWebUser, coffeeNetApps, profileApp, logoutPath);
}
Also used : List(java.util.List) CoffeeNetApp(coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp) Collections(java.util.Collections)

Example 55 with Collections

use of java.util.Collections in project kie-wb-common by kiegroup.

the class BpmnFileIndexer method buildProcessDefinition.

private List<BpmnProcessDataEventListener> buildProcessDefinition(String bpmn2Content, ClassLoader moduleClassLoader) throws IllegalArgumentException {
    if (StringUtils.isEmpty(bpmn2Content)) {
        return Collections.<BpmnProcessDataEventListener>emptyList();
    }
    // Set class loader
    KnowledgeBuilder kbuilder = null;
    if (moduleClassLoader != null) {
        KnowledgeBuilderConfigurationImpl pconf = new KnowledgeBuilderConfigurationImpl(moduleClassLoader);
        kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(pconf);
    } else {
        kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    }
    // Build
    kbuilder.add(new ByteArrayResource(bpmn2Content.getBytes()), ResourceType.BPMN2);
    if (kbuilder.hasErrors()) {
        for (KnowledgeBuilderError error : kbuilder.getErrors()) {
            logger.error("Error: {}", error.getMessage());
        }
        logger.debug("Process Cannot be Parsed! \n {} \n", bpmn2Content);
        return Collections.<BpmnProcessDataEventListener>emptyList();
    }
    // Retrieve ProcessInfoHolder
    List<BpmnProcessDataEventListener> processDataList = new ArrayList<>();
    kbuilder.getKnowledgePackages().forEach(pkg -> pkg.getProcesses().forEach(p -> {
        BpmnProcessDataEventListener processData = (BpmnProcessDataEventListener) p.getMetaData().get(BpmnProcessDataEventListener.NAME);
        processDataList.add(processData);
    }));
    return processDataList;
}
Also used : KnowledgeBuilderFactory(org.kie.internal.builder.KnowledgeBuilderFactory) XmlProcessReader(org.jbpm.compiler.xml.XmlProcessReader) KnowledgeBuilderError(org.kie.internal.builder.KnowledgeBuilderError) ModuleClassLoaderHelper(org.kie.workbench.common.services.backend.project.ModuleClassLoaderHelper) DefaultIndexBuilder(org.kie.workbench.common.services.refactoring.backend.server.indexing.DefaultIndexBuilder) Path(org.uberfire.java.nio.file.Path) ReaderResource(org.drools.core.io.impl.ReaderResource) LoggerFactory(org.slf4j.LoggerFactory) ResourceType(org.kie.api.io.ResourceType) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Package(org.guvnor.common.services.project.model.Package) ProcessValidationError(org.jbpm.process.core.validation.ProcessValidationError) Paths(org.uberfire.backend.server.util.Paths) Inject(javax.inject.Inject) ProcessValidatorRegistry(org.jbpm.process.core.validation.ProcessValidatorRegistry) BPMNSemanticModule(org.jbpm.bpmn2.xml.BPMNSemanticModule) KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) ByteArrayResource(org.drools.core.io.impl.ByteArrayResource) Module(org.guvnor.common.services.project.model.Module) SemanticModules(org.drools.core.xml.SemanticModules) AbstractFileIndexer(org.kie.workbench.common.services.refactoring.backend.server.indexing.AbstractFileIndexer) Logger(org.slf4j.Logger) Process(org.kie.api.definition.process.Process) KieModule(org.kie.workbench.common.services.shared.project.KieModule) BPMNDISemanticModule(org.jbpm.bpmn2.xml.BPMNDISemanticModule) Resource(org.kie.api.io.Resource) BPMNExtensionsSemanticModule(org.jbpm.bpmn2.xml.BPMNExtensionsSemanticModule) List(java.util.List) StringReader(java.io.StringReader) ApplicationScoped(javax.enterprise.context.ApplicationScoped) BPMNDefinitionSetResourceType(org.kie.workbench.common.stunner.bpmn.resource.BPMNDefinitionSetResourceType) Collections(java.util.Collections) ProcessValidator(org.jbpm.process.core.validation.ProcessValidator) KnowledgeBuilderError(org.kie.internal.builder.KnowledgeBuilderError) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) ArrayList(java.util.ArrayList) ByteArrayResource(org.drools.core.io.impl.ByteArrayResource)

Aggregations

Collections (java.util.Collections)113 List (java.util.List)59 ArrayList (java.util.ArrayList)41 Test (org.junit.Test)39 Map (java.util.Map)37 Collectors (java.util.stream.Collectors)34 Arrays (java.util.Arrays)28 HashMap (java.util.HashMap)26 Set (java.util.Set)25 HashSet (java.util.HashSet)23 IOException (java.io.IOException)19 Collection (java.util.Collection)19 Optional (java.util.Optional)19 TimeUnit (java.util.concurrent.TimeUnit)16 URI (java.net.URI)13 Assert (org.junit.Assert)13 Function (java.util.function.Function)12 Stream (java.util.stream.Stream)12 Before (org.junit.Before)12 Logger (org.slf4j.Logger)12