Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  The MIT License
   *
   *  Copyright 2010 Sony Ericsson Mobile Communications. All rights reserved.
   *  Copyright 2012 Sony Mobile Communications AB. All rights reserved.
   *
   *  Permission is hereby granted, free of charge, to any person obtaining a copy
   *  of this software and associated documentation files (the "Software"), to deal
   *  in the Software without restriction, including without limitation the rights
  *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  *  copies of the Software, and to permit persons to whom the Software is
  *  furnished to do so, subject to the following conditions:
  *
  *  The above copyright notice and this permission notice shall be included in
  *  all copies or substantial portions of the Software.
  *
  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  *  THE SOFTWARE.
  */
 package com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger;
 
 
 
 import java.util.List;

Displays a warning message in /manage if the Gerrit connection is down or some other warning.

Author(s):
Robert Sandell <robert.sandell@sonyericsson.com>
 
 
     private static final Logger logger = LoggerFactory.getLogger(GerritAdministrativeMonitor.class);
     private boolean connected = false;
     private boolean gerritSnapshotVersion;
     private List<GerritVersionChecker.FeaturedisabledFeatures;

    
 
     public GerritAdministrativeMonitor() {
         addThisAsConnectionListener();
     }

    
Adds this monitor as a connection listener to PluginImpl. If PluginImpl hasn't started yet, a separate Thread will be started that tries again in a little while.

 
     protected void addThisAsConnectionListener() {
         if (PluginImpl.getInstance() != null) {
              = PluginImpl.getInstance().addListener(this);
             checkGerritVersionFeatures();
         } else {
             //We were created first... let's wait without disrupting the flow.
             Runnable runner = new Runnable() {
 
                 private static final int SLEEP_INTERVAL = 500;
 
                 @Override
                 public void run() {
                     while (PluginImpl.getInstance() == null) {
                         try {
                             Thread.sleep();
                         } catch (InterruptedException ex) {
                             .debug("Got interrupted while sleeping..."ex);
                         }
                     }
                     PluginImpl plugin = PluginImpl.getInstance();
                     if (plugin != null) {
                          = plugin.addListener(GerritAdministrativeMonitor.this);
                         checkGerritVersionFeatures();
                     } else {
                         .error("Unable to register GerritAdministrativeMonitor");
                     }
                 }
             };
            Thread thread = new Thread(runner);
            thread.setDaemon(true);
            thread.start();
        }
    }

    
Tells if there is a warning with the send-commands-queue. Utility method for the jelly page.

Returns:
true if so.
    public boolean isSendQueueWarning() {
    }

    
Gets the current send-command queue size. Utility method for the jelly page.

Returns:
the amount of jobs in the queue.
    public int getSendQueueSize() {
        return GerritSendCommandQueue.getQueueSize();
    }

    
Tells if there is a connection warning. Utility method for the jelly page.

Returns:
true if so.
    @SuppressWarnings("unused")
    //called from jelly
    public boolean isConnectionWarning() {
        //If the frontend URL does not have a value, don't try to connect and show a warning
        //reminding the user to add a frontend URL.
        return !
                && PluginImpl.getInstance().getConfig().hasDefaultValues();
    }

    
Tells if there is a connection error. Utility method for the jelly page,

Returns:
true if so.
    @SuppressWarnings("unused")
    //called from jelly
    public boolean isConnectionError() {
        //If the frontend URL has a value, try to connect to it and if it is not possible,
        //show an error to the user
        return !
                && !PluginImpl.getInstance().getConfig().hasDefaultValues();
    }
    @Override
    public boolean isActivated() {
        return isConnectionWarning() || isConnectionError() || isSendQueueWarning()
                || isGerritSnapshotVersion() || hasDisabledFeatures();
    }

    
If the connected Gerrit is a snapshot version.

Returns:
true if so.
    @SuppressWarnings("unused")
    //called from jelly
    public boolean isGerritSnapshotVersion() {
        return ;
    }

    
A list of the features that has been disabled due to old Gerrit version.

Returns:
the list.
    @SuppressWarnings("unused")
    //called from jelly
        return ;
    }

    
If there are features disabled due to old Gerrit version.

Returns:
true if so.
    public boolean hasDisabledFeatures() {
        return  != null && !.isEmpty();
    }
    @Override
    public void connectionEstablished() {
         = true;
    }
    @Override
    public void connectionDown() {
         = false;
    }

    
Checks the Gerrit version that we are connected to. If it is a snapshot or if any features will be disabled because of this. It should be called whenever we got some new connection status.
    private void checkGerritVersionFeatures() {
        try {
            if () {
                GerritVersionNumber version =
                        GerritVersionChecker.createVersionNumber(PluginImpl.getInstance().getGerritVersion());
                List<GerritVersionChecker.Featurelist = new LinkedList<GerritVersionChecker.Feature>();
                for (GerritVersionChecker.Feature f : GerritVersionChecker.Feature.values()) {
                    if (!GerritVersionChecker.isCorrectVersion(versionf)) {
                        list.add(f);
                    }
                }
                this. = list;
                this. = version.isSnapshot();
            } else {
                this. = null;
                this. = false;
            }
        } catch (Exception ex) {
            .warn("Failed to calculate version info! "ex);
        }
    }
New to GrepCode? Check out our FAQ X