001package com.identityworksllc.iiq.common.plugin; 002 003import com.identityworksllc.iiq.common.service.BaseCommonService; 004import org.apache.commons.logging.Log; 005import org.apache.commons.logging.LogFactory; 006import sailpoint.api.SailPointContext; 007import sailpoint.plugin.PluginBaseHelper; 008import sailpoint.plugin.PluginContext; 009import sailpoint.tools.GeneralException; 010 011import java.sql.Connection; 012 013/** 014 * Abstract class to easily implement a Service that will only run on the 015 * alphabetically lowest Server name. This allows background execution 016 * of a task more reliably than the scheduler, but still prevents clashing 017 * if more than one server runs the task at once. 018 * 019 * Extensions should implement {@link #implementation(SailPointContext)}. 020 */ 021public abstract class SingleServerService extends BaseCommonService implements PluginContext { 022 023 /** 024 * Constructs a new service object, providing the single-service invoker 025 * as an execution model. 026 */ 027 public SingleServerService() { 028 // This determines how our service is actually invoked by the 029 // superclass. Wraps the default call to this::implementation. 030 this.invoker = (context) -> { 031 CommonPluginUtils.singleServerExecute(context, getDefinition(), this::implementation); 032 context.commitTransaction(); 033 }; 034 } 035 036 /** 037 * Required by the PluginContext interface. Implementing this here so that 038 * we don't have to implement it in every sub-class of this class. 039 * 040 * @return The plugin database connection 041 * @throws GeneralException if a DB connection failure occurs 042 */ 043 @Override 044 public Connection getConnection() throws GeneralException { 045 return PluginBaseHelper.getConnection(); 046 } 047}