|
Glassfish example source code file (PortManager.java)
The Glassfish PortManager.java source code/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright (c) 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 com.sun.enterprise.config.util; import com.sun.enterprise.config.serverbeans.Cluster; import com.sun.enterprise.config.serverbeans.Config; import com.sun.enterprise.config.serverbeans.Domain; import com.sun.enterprise.config.serverbeans.Server; import com.sun.enterprise.config.serverbeans.SystemProperty; import com.sun.enterprise.util.StringUtils; import com.sun.enterprise.util.net.*; import java.beans.PropertyVetoException; import java.util.*; import java.util.logging.*; import org.jvnet.hk2.config.TransactionFailure; /** * Hiding place for the remarkably complex logic of assigning ports to instances * GUARANTEE -- the only thing thrown from here is TransactionFailure * @author Byron Nevins */ public final class PortManager { public PortManager(Cluster cluster, Config config, Domain theDomain, Server theNewServer, Logger theLogger) throws TransactionFailure { try { if (theNewServer == null || theDomain == null) throw new TransactionFailure(Strings.get("internal.error", "null argument in PortManager constructor")); logger = theLogger; newServer = theNewServer; domain = theDomain; serverName = newServer.getName(); // bnevins 7-23-2010 // we are probably being called from inside the create decorator for a server. // the server is not yet committed. We can't call ducktype methods // on the server yet. So we do this self-serve call to get the host //host = newServer.getHost(); host = new ServerHelper(theNewServer, config).getAdminHost(); allPorts = new TreeSet<Integer>(); newServerPorts = new ServerPorts(cluster, config, domain, newServer); if (!StringUtils.ok(host)) throw new TransactionFailure(Strings.get("PortManager.noHost", serverName)); isLocal = NetUtils.isThisHostLocal(host); allServers = domain.getServers().getServer(); // why all this nonsense? ConcurrentModificationException!!! for (Iterator<Server> it = allServers.iterator(); it.hasNext();) { Server curr = it.next(); if (serverName.equals(curr.getName())) { it.remove(); } } serversOnHost = new ArrayList<ServerPorts>(); } catch (TransactionFailure tf) { throw tf; } catch (Exception e) { // this Exception will not take just a Throwable. I MUST give a string throw new TransactionFailure(e.toString(), e); } } public String process() throws TransactionFailure { try { // if there are no port system-property's -- no point in going on! if (newServerPorts.getMap().isEmpty()) return null; // all done! // make sure user-supplied props are not flaky PortUtils.checkInternalConsistency(newServer); // create a list of ALL servers running on the same machine createServerList(); // create a sorted list of every port on every other server on the same machine. populateAllPorts(); // we have a list of all possible conflicting server ports. // let's find some unused ports and reassign the variables inside // the ServerPorts class Map<String, Integer> reassigned = reassignPorts(); Set<Map.Entry Other Glassfish examples (source code examples)Here is a short list of links related to this Glassfish PortManager.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 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.