|
Glassfish example source code file (GenericJavaConfigListener.java)
The Glassfish GenericJavaConfigListener.java source code
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2009-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.
*/
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.sun.enterprise.v3.admin.listener;
import com.sun.enterprise.config.serverbeans.JavaConfig;
import com.sun.enterprise.config.serverbeans.Profiler;
import org.jvnet.hk2.config.types.Property;
import java.beans.PropertyChangeEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.Map;
import java.util.HashMap;
import java.util.Collection;
import java.util.HashSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jvnet.hk2.annotations.*;
import org.jvnet.hk2.component.PostConstruct;
import org.jvnet.hk2.config.Changed;
import org.jvnet.hk2.config.Changed.TYPE;
import org.jvnet.hk2.config.ConfigBeanProxy;
import org.jvnet.hk2.config.ConfigListener;
import org.jvnet.hk2.config.ConfigSupport;
import org.jvnet.hk2.config.NotProcessed;
import org.jvnet.hk2.config.UnprocessedChangeEvents;
/**
* Listens for the changes to the configuration of JVM and Java system
* properties (including the Java VM options). Most of the effort involves the jvm-options
* list, but restart is also required for any changes to the java-config.
* <p>
* This class is implemented so that the server restart is NOT required if a deployer wants to deploy
* an application and the application depends on a particular Java system property
* (-D) to be specified. As of now, the deployer specifies the system property
* and deploys the application and the application should find it when it does
* System.getProperty("property-name"). Here is the complete algorithm:
*
* <ol>
* <li> If any of the attributes of the java-config element (JavaConfig) change,
* this listener flags it as server-restart-required kind of change.
* </li>
* <li> If a system property is being defined and it is NOT one that starts with
* "-Djava." or "-Djavax.", it will be immediately set in the System using
* System.setProperty() call. A server restart won't be needed.
* </li>
* <li> If any other JVM option is defined that does not start with "-D" (excluding
* the cases covered above), it is deemed to be a JVM option resulting
* in server-restart-required flag set.
* </li>
* <li> If a System Property (with above distinctions) is removed, System.clearProperty()
* is called and server-restart-required flag is set accordingly.
* </li>
* </ol>
* Change in the value of a particular system property level is not handled explicitly.
* User interfaces should take a note of it. e.g. CLI does not make -Dfoo=bar and -Dfoo=bar1
* as same properties being set to two different values since it is hard to distinguish it
* in general case. Users should delete -Dfoo=bar and add -Dfoo=bar1explicitly in this case.
* @author केदार (km@dev.java.net)
* @since GlassFish V3
* @see com.sun.enterprise.config.serverbeans.JavaConfig
*/
@Service
public final class GenericJavaConfigListener implements PostConstruct, ConfigListener {
@Inject JavaConfig jc;
volatile List<String> oldProps;
/* Implementation note: See 6028*/
volatile Map<String,String> oldAttrs;
@Inject
Logger logger; //gets a root logger, which is ok for now.
public void postConstruct() {
if(jc != null && jc.getJvmOptions() != null) {
oldProps = new ArrayList<String>(jc.getJvmOptions()); //defensive copy
oldAttrs = collectAttrs(jc);
}
}
/**
Get attributes as a Map so that we can do an easy compare of old vs new and
also emit a useful change message.
<p>
This list must contain all attributes that are relevant to restart-required.
*/
private static final Map<String,String> collectAttrs(final JavaConfig jc)
{
final Map<String,String> values = new HashMap
Other Glassfish examples (source code examples)Here is a short list of links related to this Glassfish GenericJavaConfigListener.java source code file: |
| ... 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.