Author: kwright
Date: Mon Jun 24 17:30:29 2013
New Revision: 1496129
URL: http://svn.apache.org/r1496129
Log:
Add actual execution threads etc. for mapping
Added:
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/system/MappingRequest.java
(with props)
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/system/MappingThread.java
(with props)
Added:
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/system/MappingRequest.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/system/MappingRequest.java?rev=1496129&view=auto
==============================================================================
---
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/system/MappingRequest.java
(added)
+++
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/system/MappingRequest.java
Mon Jun 24 17:30:29 2013
@@ -0,0 +1,122 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.manifoldcf.authorities.system;
+
+import org.apache.manifoldcf.core.interfaces.*;
+import org.apache.manifoldcf.authorities.interfaces.*;
+import java.util.*;
+
+/** This class describes a user mapping request. The request has state: It
can be in an incomplete state, or it can be in a complete state.
+* The thread that cares whether the request is complete needs to be able to
wait for that situation to occur, so the request has
+* a method that does just that.
+*/
+public class MappingRequest
+{
+ public static final String _rcsid = "@(#)$Id$";
+
+ // This is where the request data actually lives
+ protected final UserRecord userRecord;
+ protected final String className;
+ protected final String identifyingString;
+ protected final ConfigParams configParameters;
+ protected final int maxConnections;
+
+ // These are the possible results of the request
+ protected boolean answerComplete = false;
+ protected Throwable answerException = null;
+
+ /** Construct the request, and record the question.
+ */
+ public MappingRequest(UserRecord userRecord, String className, String
identifyingString, ConfigParams configParameters, int maxConnections)
+ {
+ this.userRecord = userRecord;
+ this.className = className;
+ this.identifyingString = identifyingString;
+ this.configParameters = configParameters;
+ this.maxConnections = maxConnections;
+ }
+
+ /** Get the user record */
+ public UserRecord getUserRecord()
+ {
+ return userRecord;
+ }
+
+ /** Get the class name */
+ public String getClassName()
+ {
+ return className;
+ }
+
+ /** Get the identifying string, to pass back to the user if there was a
problem */
+ public String getIdentifyingString()
+ {
+ return identifyingString;
+ }
+
+ /** Get the configuration parameters */
+ public ConfigParams getConfigurationParams()
+ {
+ return configParameters;
+ }
+
+ /** Get the maximum number of connections */
+ public int getMaxConnections()
+ {
+ return maxConnections;
+ }
+
+ /** Wait for an auth request to be complete.
+ */
+ public void waitForComplete()
+ throws InterruptedException
+ {
+ synchronized (this)
+ {
+ if (answerComplete)
+ return;
+ this.wait();
+ }
+ }
+
+ /** Note that the request is complete, and record the answers.
+ */
+ public void completeRequest(Throwable answerException)
+ {
+ synchronized (this)
+ {
+ if (answerComplete)
+ return;
+
+ // Record the answer.
+ answerComplete = true;
+ this.answerException = answerException;
+
+ // Notify threads waiting on the answer.
+ this.notifyAll();
+ }
+ }
+
+ /** Get the answer exception */
+ public Throwable getAnswerException()
+ {
+ return answerException;
+ }
+
+}
Propchange:
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/system/MappingRequest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/system/MappingRequest.java
------------------------------------------------------------------------------
svn:keywords = Id
Added:
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/system/MappingThread.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/system/MappingThread.java?rev=1496129&view=auto
==============================================================================
---
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/system/MappingThread.java
(added)
+++
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/system/MappingThread.java
Mon Jun 24 17:30:29 2013
@@ -0,0 +1,150 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.manifoldcf.authorities.system;
+
+import org.apache.manifoldcf.core.interfaces.*;
+import org.apache.manifoldcf.agents.interfaces.*;
+import org.apache.manifoldcf.authorities.interfaces.*;
+import org.apache.manifoldcf.authorities.system.Logging;
+import java.util.*;
+import java.lang.reflect.*;
+
+/** This thread performs actual user mapping operations.
+*/
+public class MappingThread extends Thread
+{
+ public static final String _rcsid = "@(#)$Id$";
+
+ // Local data
+ protected RequestQueue<MappingRequest> requestQueue;
+
+ /** Constructor.
+ */
+ public MappingThread(String id, RequestQueue<MappingRequest> requestQueue)
+ throws ManifoldCFException
+ {
+ super();
+ this.requestQueue = requestQueue;
+ setName("Mapping thread "+id);
+ setDaemon(true);
+ }
+
+ public void run()
+ {
+ // Create a thread context object.
+ IThreadContext threadContext = ThreadContextFactory.make();
+
+ // Loop
+ while (true)
+ {
+ // Do another try/catch around everything in the loop
+ try
+ {
+ if (Thread.currentThread().isInterrupted())
+ throw new
ManifoldCFException("Interrupted",ManifoldCFException.INTERRUPTED);
+
+ // Wait for a request.
+ MappingRequest theRequest = requestQueue.getRequest();
+
+ // Try to fill the request before going back to sleep.
+ if (Logging.authorityService.isDebugEnabled())
+ {
+ Logging.authorityService.debug(" Calling mapping connector class
'"+theRequest.getClassName()+"'");
+ }
+
+ Throwable exception = null;
+
+ try
+ {
+ IMappingConnector connector =
MappingConnectorFactory.grab(threadContext,
+ theRequest.getClassName(),
+ theRequest.getConfigurationParams(),
+ theRequest.getMaxConnections());
+ try
+ {
+ if (connector == null)
+ exception = new ManifoldCFException("Mapping connector
"+theRequest.getClassName()+" is not registered.");
+ else
+ {
+ // Do the mapping
+ try
+ {
+ connector.mapUser(theRequest.getUserRecord());
+ }
+ catch (ManifoldCFException e)
+ {
+ if (e.getErrorCode() == ManifoldCFException.INTERRUPTED)
+ throw e;
+ Logging.authorityService.warn("Mapping error:
"+e.getMessage(),e);
+ }
+
+ }
+ }
+ finally
+ {
+ MappingConnectorFactory.release(connector);
+ }
+ }
+ catch (ManifoldCFException e)
+ {
+ if (e.getErrorCode() == ManifoldCFException.INTERRUPTED)
+ throw e;
+ Logging.authorityService.warn("Mapping connection exception:
"+e.getMessage(),e);
+ exception = e;
+ }
+ catch (Throwable e)
+ {
+ Logging.authorityService.warn("Mapping connection error:
"+e.getMessage(),e);
+ exception = e;
+ }
+
+ // The request is complete
+ theRequest.completeRequest(exception);
+
+ // Repeat, and only go to sleep if there are no more requests.
+ }
+ catch (ManifoldCFException e)
+ {
+ if (e.getErrorCode() == ManifoldCFException.INTERRUPTED)
+ break;
+
+ // Log it, but keep the thread alive
+ Logging.authorityService.error("Exception tossed: "+e.getMessage(),e);
+
+ if (e.getErrorCode() == ManifoldCFException.SETUP_ERROR)
+ {
+ // Shut the whole system down!
+ System.exit(1);
+ }
+
+ }
+ catch (InterruptedException e)
+ {
+ // We're supposed to quit
+ break;
+ }
+ catch (Throwable e)
+ {
+ // A more severe error - but stay alive
+ Logging.authorityService.fatal("Error tossed: "+e.getMessage(),e);
+ }
+ }
+ }
+
+}
Propchange:
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/system/MappingThread.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
manifoldcf/branches/CONNECTORS-703/framework/pull-agent/src/main/java/org/apache/manifoldcf/authorities/system/MappingThread.java
------------------------------------------------------------------------------
svn:keywords = Id