View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.core.provisioning.java.pushpull;
20  
21  import java.util.concurrent.RejectedExecutionException;
22  import org.apache.syncope.core.persistence.api.entity.task.PushTask;
23  import org.apache.syncope.core.provisioning.api.pushpull.ProvisioningProfile;
24  import org.apache.syncope.core.provisioning.api.pushpull.PushActions;
25  import org.apache.syncope.core.provisioning.api.pushpull.SyncopePushExecutor;
26  import org.apache.syncope.core.provisioning.api.pushpull.SyncopePushResultHandler;
27  
28  public class PushResultHandlerDispatcher
29          extends SyncopeResultHandlerDispatcher<PushTask, PushActions, SyncopePushResultHandler> {
30  
31      protected final SyncopePushExecutor executor;
32  
33      public PushResultHandlerDispatcher(
34              final ProvisioningProfile<PushTask, PushActions> profile,
35              final SyncopePushExecutor executor) {
36  
37          super(profile);
38          this.executor = executor;
39      }
40  
41      public boolean handle(final String anyType, final String anyKey) {
42          if (executor.wasInterruptRequested()) {
43              LOG.debug("Push interrupted");
44              executor.setInterrupted();
45              return false;
46          }
47  
48          if (tpte.isEmpty()) {
49              boolean result = nonConcurrentHandler(anyType).handle(anyKey);
50  
51              executor.reportHandled(anyType, anyKey);
52  
53              return result;
54          }
55  
56          try {
57              submit(() -> {
58                  suppliers.get(anyType).get().handle(anyKey);
59  
60                  executor.reportHandled(anyType, anyKey);
61              });
62              return true;
63          } catch (RejectedExecutionException e) {
64              LOG.error("Could not submit push handler for {} {}", anyType, anyKey);
65              return false;
66          }
67      }
68  }