Package org.jboss.dna.graph.request.processor

Examples of org.jboss.dna.graph.request.processor.RequestProcessor


         */
        public void execute( ExecutionContext context,
                             Request request ) throws RepositorySourceException {
            if (request instanceof AccessQueryRequest) {
                AccessQueryRequest queryRequest = (AccessQueryRequest)request;
                RequestProcessor searchProcessor = searchEngine().createProcessor(context, null, true);
                try {
                    searchProcessor.process(queryRequest);
                } finally {
                    searchProcessor.close();
                }
            } else if (request instanceof FullTextSearchRequest) {
                FullTextSearchRequest searchRequest = (FullTextSearchRequest)request;
                RequestProcessor searchProcessor = searchEngine().createProcessor(context, null, true);
                try {
                    searchProcessor.process(searchRequest);
                } finally {
                    searchProcessor.close();
                }
            } else if (request instanceof CompositeRequest) {
                CompositeRequest composite = (CompositeRequest)request;
                CompositeRequestChannel channel = null;
                RequestProcessor searchProcessor = null;
                try {
                    for (Request nested : composite) {
                        if (nested instanceof AccessQueryRequest) {
                            AccessQueryRequest queryRequest = (AccessQueryRequest)request;
                            if (searchProcessor == null) searchProcessor = searchEngine().createProcessor(context, null, true);
                            searchProcessor.process(queryRequest);
                        } else if (nested instanceof FullTextSearchRequest) {
                            FullTextSearchRequest searchRequest = (FullTextSearchRequest)request;
                            if (searchProcessor == null) searchProcessor = searchEngine().createProcessor(context, null, true);
                            searchProcessor.process(searchRequest);
                        } else {
                            // Delegate to the channel ...
                            if (channel == null) {
                                // Create a connection factory that always returns the delegate connection ...
                                RepositoryConnectionFactory connectionFactory = new RepositoryConnectionFactory() {
                                    /**
                                     * {@inheritDoc}
                                     *
                                     * @see org.jboss.dna.graph.connector.RepositoryConnectionFactory#createConnection(java.lang.String)
                                     */
                                    public RepositoryConnection createConnection( String sourceName )
                                        throws RepositorySourceException {
                                        assert delegate().getName().equals(sourceName);
                                        return delegateConnection();
                                    }
                                };
                                channel = new CompositeRequestChannel(delegate().getName());
                                channel.start(executorService, context, connectionFactory);
                            }
                            channel.add(request);
                        }
                    }
                } finally {
                    try {
                        if (searchProcessor != null) {
                            searchProcessor.close();
                        }
                    } finally {
                        if (channel != null) {
                            try {
                                channel.close();
View Full Code Here


         */
        public void execute( final ExecutionContext context,
                             final Request request ) throws RepositorySourceException {
            if (request instanceof AccessQueryRequest) {
                AccessQueryRequest queryRequest = (AccessQueryRequest)request;
                RequestProcessor searchProcessor = searchEngine().createProcessor(context, null, true);
                try {
                    searchProcessor.process(queryRequest);
                } finally {
                    searchProcessor.close();
                }
            } else if (request instanceof FullTextSearchRequest) {
                FullTextSearchRequest searchRequest = (FullTextSearchRequest)request;
                RequestProcessor searchProcessor = searchEngine().createProcessor(context, null, true);
                try {
                    searchProcessor.process(searchRequest);
                } finally {
                    searchProcessor.close();
                }
            } else if (request instanceof CompositeRequest) {
                CompositeRequest composite = (CompositeRequest)request;
                List<Request> delegateRequests = null;
                RequestProcessor searchProcessor = null;
                try {
                    Request delegateRequest = composite;
                    for (Request nested : composite) {
                        if (nested instanceof AccessQueryRequest) {
                            AccessQueryRequest queryRequest = (AccessQueryRequest)request;
                            if (searchProcessor == null) searchProcessor = searchEngine().createProcessor(context, null, true);
                            searchProcessor.process(queryRequest);
                            delegateRequest = null;
                        } else if (nested instanceof FullTextSearchRequest) {
                            FullTextSearchRequest searchRequest = (FullTextSearchRequest)request;
                            if (searchProcessor == null) searchProcessor = searchEngine().createProcessor(context, null, true);
                            searchProcessor.process(searchRequest);
                            delegateRequest = null;
                        } else {
                            // Delegate the request ...
                            if (delegateRequests == null) {
                                delegateRequests = new LinkedList<Request>();
                            }
                            delegateRequests.add(request);
                        }
                    }
                    if (delegateRequest == null) {
                        // Then there was at least one query or search request ...
                        if (delegateRequests != null) {
                            // There was other requests ...
                            assert !delegateRequests.isEmpty();
                            delegateRequest = CompositeRequest.with(delegateRequests);
                            delegateConnection().execute(context, delegateRequest);
                        } else {
                            // There were no other requests in the composite other than the search and/or query requests ...
                            // So nothing to do ...
                        }
                    } else {
                        // There were no search or query requests, so delegate the orginal composite request ...
                        delegateConnection().execute(context, request);
                    }
                } finally {
                    if (searchProcessor != null) {
                        searchProcessor.close();
                    }
                }
            } else {
                // Just a single, non-query and non-search request ...
                delegateConnection().execute(context, request);
View Full Code Here

     *      org.jboss.dna.graph.request.Request)
     */
    public void execute( final ExecutionContext context,
                         final Request request ) throws RepositorySourceException {

        RequestProcessor processor = new SVNRepositoryRequestProcessor(sourceName, defaultWorkspace, availableWorkspaceNames,
                                                                       creatingWorkspacesAllowed, context, updatesAllowed,
                                                                       accessData);
        try {
            processor.process(request);
        } finally {
            processor.close();
        }
    }
View Full Code Here

     *      org.jboss.dna.graph.request.Request)
     */
    public void execute( ExecutionContext context,
                         Request request ) throws RepositorySourceException {
        // create processor and delegate handling
        RequestProcessor proc = new JdbcRequestProcesor(getSourceName(), context, connection, rootNodeUuid);
        try {
            proc.process(request);
        } finally {
            proc.close();
        }
    }
View Full Code Here

        // Prepare for trace-level logging ...
        if (stopwatch != null) stopwatch.start();

        boolean abort = false;
        RequestProcessor processorWithEvents = null;
        try {
            // ----------------------------------------------------------------------------------------------------
            // Step 1: Fork the submitted requests into source-specific requests...
            // ----------------------------------------------------------------------------------------------------
            // This forks a subtask for each source, as soon as the first source-specific request for a source
            // is generated. Each source's "execute(ExecutionContext,Request)" is called only once (a queue is
            // used so that the source can begin processing the requests before all the requests have been
            // computed and submitted to the subtask). Thus, it's possible (and likely) that this thread
            // and subtask threads are executed in parallel.
            final Queue<FederatedRequest> requests = awaitAllSubtasks ? new LinkedList<FederatedRequest>() : new LinkedBlockingQueue<FederatedRequest>();
            final ForkRequestProcessor fork = new ForkRequestProcessor(repository, context, nowInUtc, requests);
            if (synchronousStep1) {
                // Execute the forking process in this thread ...
                try {
                    fork.process(request);
                } finally {
                    fork.close();
                }
                requests.add(new NoMoreFederatedRequests());
                // At this point, all submitted requests have been processed/forked, so we can continue with
                // the join process, starting with the first submitted request. Note that the subtasks may
                // still be executing, but as the join process operates on a forked request, it will wait
                // until all forked requests have completed. Hopefully, in most situations, the subtasks
                // have enough of a lead that the join process never has to wait.
            } else {
                // Submit the forking process for execution in a separate thread ...
                repository.getExecutor().submit(new Runnable() {
                    public void run() {
                        try {
                            fork.process(request);
                        } finally {
                            fork.close();
                        }
                        requests.add(new NoMoreFederatedRequests());
                    }
                });

                // At this point, the forking process is being run by a thread owned by the Executor. We'll still
                // continue with the join process, starting with the first submitted request. Note that it is
                // likely that the subtasks are still running in threads owned by the Executor.
            }

            if (awaitAllSubtasks) {
                // Await until all subtasks have completed ...
                fork.await();
            }

            // ----------------------------------------------------------------------------------------------------
            // Step 2: Join the results of the source-specific (forked) requests back into the submitted requests
            // ----------------------------------------------------------------------------------------------------
            JoinRequestProcessor join = new JoinRequestProcessor(repository, context, observer, nowInUtc);
            try {
                if (awaitAllSubtasks) {
                    join.process(requests);
                } else {
                    join.process((BlockingQueue<FederatedRequest>)requests);
                }
            } catch (RuntimeException e) {
                abort = true;
                throw e;
            } finally {
                if (!awaitAllSubtasks) {
                    // We need to guarantee that the fork processor is closed and released all its resources before we close
                    // ...
                    fork.await();
                }
                join.close();
                processorWithEvents = join;
            }
            if (request instanceof CompositeRequest) {
                // The composite request will not have any errors set, since the fork/join approach puts the
                // contained requests into a separate CompositeRequest object for processing.
                // So, look at the requests for any errors
                ((CompositeRequest)request).checkForErrors();
            }
            if (request.hasError() && !request.isReadOnly()) {
                // There are changes and there is at least one failure ...
                abort = true;
            }
        } catch (InterruptedException e) {
            abort = true;
            request.setError(e);
        } catch (ExecutionException e) {
            abort = true;
            request.setError(e);
        } catch (CancellationException e) {
            abort = true;
            request.cancel();
            // do nothing else
        } catch (RuntimeException e) {
            abort = true;
            throw e;
        } finally {
            if (stopwatch != null) stopwatch.stop();
            if (abort) {
                // Rollback the transaction (if there is one) ...
            } else {
                // fire off any notifications to the observer ...
                assert processorWithEvents != null;
                processorWithEvents.notifyObserverOfChanges();
            }
        }
    }
View Full Code Here

            sw.start();
        }
        // Do any commands update/write?
        RepositoryContext repositoryContext = this.source.getRepositoryContext();
        Observer observer = repositoryContext != null ? repositoryContext.getObserver() : null;
        RequestProcessor processor = new MapRequestProcessor(context, this.repository, observer, source.areUpdatesAllowed());

        boolean commit = true;
        MapRepositoryTransaction txn = repository.startTransaction(request.isReadOnly());
        try {
            // Obtain the lock and execute the commands ...
            processor.process(request);
            if (request.hasError() && !request.isReadOnly()) {
                // The changes failed, so we need to rollback so we have 'all-or-nothing' behavior
                commit = false;
            }
        } catch (Throwable error) {
            commit = false;
        } finally {
            try {
                processor.close();
            } finally {
                // Now commit or rollback ...
                try {
                    if (commit) {
                        txn.commit();
                    } else {
                        // Need to rollback the changes made to the repository ...
                        txn.rollback();
                    }
                } catch (Throwable commitOrRollbackError) {
                    if (commit && !request.hasError() && !request.isFrozen()) {
                        // Record the error on the request ...
                        request.setError(commitOrRollbackError);
                    }
                    commit = false; // couldn't do it
                }
                if (commit) {
                    // Now that we've closed our transaction, we can notify the observer of the committed changes ...
                    processor.notifyObserverOfChanges();
                }
            }
        }
        if (logger.isTraceEnabled()) {
            assert sw != null;
View Full Code Here

     *      org.jboss.dna.graph.request.Request)
     */
    public void execute( ExecutionContext context,
                         Request request ) throws RepositorySourceException {
        long size = largeValueMinimumSizeInBytes;
        RequestProcessor proc = model.createRequestProcessor(name,
                                                             context,
                                                             entityManager,
                                                             rootNodeUuid,
                                                             nameOfDefaultWorkspace,
                                                             predefinedWorkspaceNames,
                                                             size,
                                                             creatingWorkspacesAllowed,
                                                             compressData,
                                                             enforceReferentialIntegrity);
        try {
            proc.process(request);
        } finally {
            proc.close();
        }
    }
View Full Code Here

    protected QueryResults search( String workspaceName,
                                   String searchExpression,
                                   int maxResults,
                                   int offset ) {
        RequestProcessor processor = engine.createProcessor(context, null, true);
        try {
            FullTextSearchRequest request = new FullTextSearchRequest(searchExpression, workspaceName, maxResults, offset);
            processor.process(request);
            if (request.hasError()) {
                fail(request.getError().getMessage());
                return null;
            }
            assertThat(request.getResultColumns().getColumnCount(), is(0));
            assertThat(request.getResultColumns().getLocationCount(), is(1));
            assertThat(request.getResultColumns().hasFullTextSearchScores(), is(true));
            // Convert the results to a List<Location>
            List<Object[]> tuples = request.getTuples();
            List<Location> results = new ArrayList<Location>(tuples.size());
            for (Object[] tuple : tuples) {
                results.add((Location)tuple[0]);
                Float score = (Float)tuple[1];
                assertThat(score, is(notNullValue()));
            }
            return new org.jboss.dna.graph.query.process.QueryResults(request.getResultColumns(), request.getStatistics(),
                                                                      request.getTuples());
        } finally {
            processor.close();
        }
    }
View Full Code Here

        SelectorName tableName = ((Selector)source).getName();
        Constraint constraint = query.getConstraint();
        Columns resultColumns = new QueryResultColumns(query.getColumns(), QueryResultColumns.includeFullTextScores(constraint));
        List<Constraint> andedConstraints = getAndedConstraint(constraint, new ArrayList<Constraint>());
        Limit limit = query.getLimits();
        RequestProcessor processor = engine.createProcessor(context, null, true);
        try {
            AccessQueryRequest request = new AccessQueryRequest(workspaceName, tableName, resultColumns, andedConstraints, limit,
                                                                schemata, variables);
            processor.process(request);
            if (request.hasError()) {
                fail(request.getError().getMessage());
            }
            return new org.jboss.dna.graph.query.process.QueryResults(request.resultColumns(), request.getStatistics(),
                                                                      request.getTuples());
        } finally {
            processor.close();
        }
    }
View Full Code Here

        if (logger.isTraceEnabled()) {
            sw = new Stopwatch();
            sw.start();
        }
        // Do any commands update/write?
        RequestProcessor processor = new MapRequestProcessor(context, this.repository, this.source.getRepositoryContext());

        Lock lock = request.isReadOnly() ? repository.getLock().readLock() : repository.getLock().writeLock();
        lock.lock();
        try {
            // Obtain the lock and execute the commands ...
            processor.process(request);
        } finally {
            try {
                processor.close();
            } finally {
                lock.unlock();
            }
        }
        if (logger.isTraceEnabled()) {
View Full Code Here

TOP

Related Classes of org.jboss.dna.graph.request.processor.RequestProcessor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.