|
Glassfish example source code file (AutodeployRetryManager.java)
The Glassfish AutodeployRetryManager.java source code
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2008-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package org.glassfish.deployment.autodeploy;
import com.sun.enterprise.config.serverbeans.DasConfig;
import com.sun.enterprise.util.LocalStringManagerImpl;
import com.sun.logging.LogDomains;
import java.io.File;
import java.util.Date;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.glassfish.api.ActionReport;
import org.glassfish.api.Async;
import org.glassfish.deployment.autodeploy.AutoDeployer.AutodeploymentStatus;
import org.glassfish.deployment.common.DeploymentUtils;
import org.jvnet.hk2.annotations.Inject;
import org.jvnet.hk2.annotations.Scoped;
import org.jvnet.hk2.annotations.Service;
import org.jvnet.hk2.component.PostConstruct;
import org.jvnet.hk2.component.Singleton;
/**
* Manages retrying of autodeployed files in case a file is copied slowly.
* <p>
* If a file is copied into the autodeploy directory slowly, it can appear there
* before the copy operation has finished, causing the attempt to autodeploy it to fail.
* This class encapsulates logic to decide whether to retry the deployment of
* such files on successive loops through
* the autodeployer thread, reporting failure only if the candidate file has
* failed to deploy earlier and has remained stable in size for a
* (configurable) period of time.
* <p>
* The main public entry point are the {@link �} method and
* the {@link reportSuccessfulDeployment},
* {@link reportFailedDeployment}, {@link reportSuccessfulUndeployment}, and
* {@link reportUnsuccessfulUndeployment} methods.
* <p>
* The client should invoke {@link shouldAttemptDeployment} when it has identified
* a candidate file for deployment but before trying to deploy that file. This
* retry manager will return whether the caller should attempt to deploy the file,
* at least based on whether there has been a previous unsuccessful attempt to
* deploy it and, if so, whether the file seems to be stable in size or not.
* <p>
* When the caller actually tries to deploy a file, it must invoke
* {@link reportSuccessfulDeployment} or {@link reportFailedDeployment)
* so that the retry manager keeps its information about the file up-to-date.
* Similarly, when the caller tries to undeploy a file it must invoke
* {@link reportSuccessfulUndeployment} or {@link reportFailedUndeployment}.
* <P>
* Internally for each file that has failed to deploy the retry manager records
* the file's size and the timestamp of the most recent failure and the timestamp at
* which that file will be assumed to be fully copied. At that time the file's
* retry period will expire. This retry expiration value is extended each time
* the file changes size since the last time it was checked.
* <p>
* If AutoDeployer previously reported failures to deploy the file and the
* file's size has been stable for its retry expiration time, then the
* {@link shouldAttemptDeployment} method returns true to trigger another attempt to
* deploy the file. If the autodeployer reports another failed deployment
* then the retry manager concludes that the file is not simply a slow-copying
* file but is truly invalid. In that case
* it throws an exception.
* <p>
* Once the caller reports a successful deployment of a file by invoking
* {@link reportSuccessfulDeployment} the retry manager discards any record of
* that file from its internal data structures. Similarly the retry manager
* stops monitoring a file once the autodeployer has made an attempt -
* successful or unsuccessful - to undeploy it.
* <p>
* An important change from v2 to v3 is the change in the default retry limit.
* In v2 we could try to open a file as a ZIP file to help decide if it had
* finished copying, but in v3 we cannot make assumptions about how apps
* will be packaged (some may be ZIPs, but others may be single files). We
* need to provide a balance between prompt reporting of a failed auto-deployment
* vs. handling the case of a slow copy operation which, for a while, manifests
* itself as a failed deployment.
*
* @author tjquinn
*/
@Service
@Scoped(Singleton.class)
public class AutodeployRetryManager implements PostConstruct {
/**
*Specifies the default value for the retry limit.
*/
private static final int RETRY_LIMIT_DEFAULT = 4; // 4 seconds but default is really set on DasConfig in config-api
/** Maps an invalid File to its corresponding Info object. */
private HashMap<File,Info> invalidFiles = new HashMap |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.