LISTSERV mailing list manager LISTSERV 16.5

Help for HPS-SVN Archives


HPS-SVN Archives

HPS-SVN Archives


HPS-SVN@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

HPS-SVN Home

HPS-SVN Home

HPS-SVN  February 2016

HPS-SVN February 2016

Subject:

r4234 - /java/branches/jeremy-dev/job/src/main/java/org/hps/job/DatabaseConditionsManagerSetup.java

From:

[log in to unmask]

Reply-To:

Notification of commits to the hps svn repository <[log in to unmask]>

Date:

Wed, 17 Feb 2016 21:28:45 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (139 lines)

Author: [log in to unmask]
Date: Wed Feb 17 13:28:43 2016
New Revision: 4234

Log:
Add setup helper class for database conditions manager.

Added:
    java/branches/jeremy-dev/job/src/main/java/org/hps/job/DatabaseConditionsManagerSetup.java

Added: java/branches/jeremy-dev/job/src/main/java/org/hps/job/DatabaseConditionsManagerSetup.java
 =============================================================================
--- java/branches/jeremy-dev/job/src/main/java/org/hps/job/DatabaseConditionsManagerSetup.java	(added)
+++ java/branches/jeremy-dev/job/src/main/java/org/hps/job/DatabaseConditionsManagerSetup.java	Wed Feb 17 13:28:43 2016
@@ -0,0 +1,123 @@
+package org.hps.job;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.hps.conditions.database.DatabaseConditionsManager;
+import org.hps.detector.svt.SvtDetectorSetup;
+import org.hps.run.database.RunManager;
+import org.lcsim.conditions.ConditionsListener;
+import org.lcsim.job.DefaultConditionsSetup;
+
+/**
+ * Provides setup for HPS specific conditions manager.
+ * 
+ * @author Jeremy McCormick, SLAC
+ *
+ */
+public final class DatabaseConditionsManagerSetup extends DefaultConditionsSetup {
+
+    private Logger LOGGER = Logger.getLogger(DatabaseConditionsManagerSetup.class.getPackage().getName());   
+    private boolean enableRunManager = true;
+    private Set<String> tags = null;
+    private boolean freeze = false;
+    
+    /**
+     * Set whether system should be frozen after initialization.
+     * @param freeze <code>true</code> to freeze conditions after initialization
+     */
+    public void setFreeze(boolean freeze) {
+        this.freeze = freeze;
+    }
+    
+    /**
+     * Enable the run manager in the job.
+     * @param enableRunManager <code>true</code> to enable run manager
+     */
+    public void setEnableRunManager(boolean enableRunManager) {
+        this.enableRunManager = enableRunManager;
+    }
+    
+    /**
+     * Set the set of tags for filtering conditions records.
+     * @param tags the set of tags for filtering conditions records
+     */
+    public void setTags(Set<String> tags) {
+        this.tags = tags;
+    }
+
+    /**
+     * Configure the conditions system before it is initialized.
+     * <p>
+     * An SVT specific setup class is added to the manager here.
+     * <p>
+     * This method will also optionally setup the {@link org.hps.run.database.RunManager} 
+     * and can pass a set of tags to the conditions manager.
+     */
+    @Override
+    public void configure() {
+            
+        // Initialize the db conditions manager.
+        DatabaseConditionsManager conditionsManager = DatabaseConditionsManager.getInstance();
+        
+        if (enableRunManager) {
+            LOGGER.config("adding run manager conditions listener");
+            conditionsManager.addConditionsListener(RunManager.getRunManager());
+        }
+        
+        // Add class that will setup SVT detector with conditions data.
+        LOGGER.config("adding SVT detector setup conditions listener");
+        conditionsManager.addConditionsListener(new SvtDetectorSetup());
+                        
+        // Add conditions system tags.
+        if (this.tags != null) {
+            LOGGER.config("adding tags " + tags.toString());
+            conditionsManager.addTags(tags);
+        }
+        
+        // Add extra listeners to manager.
+        for (ConditionsListener listener : listeners) {
+            conditionsManager.addConditionsListener(listener);
+        }
+    }
+     
+    /**
+     * Do post initialization of conditions system, which will freeze the manager if it
+     * is fully initialized (meaning detector name and run were given as arguments to override
+     * the information from the data).
+     */
+    @Override
+    public void postInitialize() {
+        if (DatabaseConditionsManager.getInstance().isInitialized() || this.freeze) {
+            LOGGER.config("Job manager is freezing the conditions system.");
+            DatabaseConditionsManager.getInstance().freeze();
+        }
+    }
+    
+    /**
+     * Do cleanup of conditions system after job.
+     * <p>
+     * Shuts down the database connections to the run manager and conditions manager, if necessary.
+     */
+    @Override
+    public void cleanup() {
+        
+        // Close the conditions database connection.
+        Connection connection = DatabaseConditionsManager.getInstance().getConnection();
+        try {
+            if (connection != null && !connection.isClosed()) {
+                DatabaseConditionsManager.getInstance().closeConnection();
+            }
+        } catch (SQLException e) {
+            LOGGER.log(Level.WARNING, e.getMessage(), e);
+        }
+                        
+        // Close the run manager connection.
+        if (enableRunManager) {
+            RunManager.getRunManager().closeConnection();
+        }
+    }
+}

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

November 2017
August 2017
July 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use