View Javadoc
1   /**
2    * Copyright 2004-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.kpme.core.batch;
17  
18  import org.apache.log4j.Logger;
19  import org.kuali.kpme.core.KPMEConstants;
20  import org.kuali.kpme.core.util.HrConstants;
21  import org.kuali.rice.core.api.config.property.ConfigContext;
22  import org.kuali.rice.kim.api.identity.principal.Principal;
23  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
24  import org.quartz.*;
25  
26  import java.net.InetAddress;
27  import java.net.UnknownHostException;
28  import java.util.Iterator;
29  
30  public abstract class BatchJob implements StatefulJob {
31      private static final Logger LOG = Logger.getLogger(BatchJob.class);
32      private transient Thread workerThread;
33  
34  
35      protected String jobDataMapToString(JobDataMap jobDataMap) {
36          StringBuilder buf = new StringBuilder();
37          buf.append("{");
38          Iterator keys = jobDataMap.keySet().iterator();
39          boolean hasNext = keys.hasNext();
40          while (hasNext) {
41              String key = (String) keys.next();
42              Object value = jobDataMap.get(key);
43              buf.append(key).append("=");
44              if (value == jobDataMap) {
45                  buf.append("(this map)");
46              }
47              else {
48                  buf.append(value);
49              }
50              hasNext = keys.hasNext();
51              if (hasNext) {
52                  buf.append(", ");
53              }
54          }
55          buf.append("}");
56          return buf.toString();
57      }
58  
59      protected String getMachineName() {
60          try {
61              return InetAddress.getLocalHost().getHostName();
62          }
63          catch (UnknownHostException e) {
64              return "Unknown";
65          }
66      }
67  
68      protected String getBatchUserPrincipalId() {
69          return BatchJobUtil.getBatchUserPrincipalId();
70      }
71  
72      protected String getBatchUserPrincipalName() {
73          return BatchJobUtil.getBatchUserPrincipalName();
74      }
75  
76  }