- 论坛徽章:
- 0
|
本帖最后由 三人行必有吾师 于 2012-05-19 07:54 编辑
回复 92# 鸣禽云霞出海曙
至于WebLogic,前面有位同学说得好,可以反编译weblogic.jar文件;先解压缩,再用Jad之类的工具,基本上可以倒腾出个大概;只是其中没有了注释和变量名的准确定义,所以需要读代码的能力超强。。。
其实WebLogic的代码和大家熟悉的Java代码类似(不过NativeIO那块有JNI调C),比如ClusterService.java- package weblogic.cluster;
- import java.io.IOException;
- import java.net.InetAddress;
- import java.net.UnknownHostException;
- import java.util.Collection;
- import weblogic.cluster.replication.ReplicationManager;
- import weblogic.common.internal.VersionInfo;
- import weblogic.kernel.Kernel;
- import weblogic.management.Admin;
- import weblogic.management.configuration.ClusterMBean;
- import weblogic.management.configuration.ServerMBean;
- import weblogic.rjvm.JVMID;
- import weblogic.rmi.spi.RMIRuntime;
- import weblogic.server.Server;
- import weblogic.server.ServerLifeCycle;
- import weblogic.server.ServerLifecycleException;
- /**
- * Implements lifecycle for internal cluster service. This controls
- * features of the cluster subsystem that are used by other subsystems.
- * It is inialized early in server startup to ensure that other
- * subsystems can use can access its services during initialization.
- * This class also the ClusterServices interface, which gives other
- * subsystems access to clustering machinery.
- *
- * @author Copyright (c) 1996-98 by WebLogic, Inc. All Rights Reserved.
- * @author Copyright (c) 1999-2000 by BEA WebXpress. All Rights Reserved.
- */
- final public class ClusterService implements ServerLifeCycle, ClusterServices
- {
- private static ClusterService singleton = null;
- private static boolean clusterMemberInitialized = false;
- /* package */ static final String MULTICAST_QUEUE = "Multicast";
- private static final ClusterTextTextFormatter formatter =
- new ClusterTextTextFormatter();
- public ClusterService() {
- singleton = this;
- }
- /** This accessor is ONLY for the server initialization mechanism.
- * If you are a client, use the static getServices() call instead.
- */
- public static ClusterService getClusterService() {
- return singleton;
- }
- private ClusterMBean clusterMBean;
- private MemberAttributes localAttributes;
- private static boolean isServerInCluster = false;
- private String clusterName;
- public void initialize()
- throws ServerLifecycleException
- {
- ServerMBean serverMBean = Server.getConfig();
- clusterMBean = serverMBean.getCluster();
- String machineName = (serverMBean.getMachine() == null) ?
- Kernel.getConfig().getName() : serverMBean.getMachine().getName();
- if (clusterMBean != null) {
- // Set ServerInfo on local server
- weblogic.rmi.cluster.ServerInfoManager.theOne().addServer(
- serverMBean.getName(),
- RMIRuntime.getLocalHostID(),
- serverMBean.getClusterWeight()
- );
- // Figure out the multicast address for the cluster
- clusterName = clusterMBean.getName();
- String address = clusterMBean.getMulticastAddress();
- if (address == null || address.equals("")) {
- // may be null if config entry is missing
- // do not provide any default multicast address but flag a config error
- ClusterLogger.logMissingClusterMulticastAddressError(clusterName);
- // we can not go ahead, stop the ongoing startupMode
- throw new ServerLifecycleException(
- "configuration problem - missing multicast address for cluster: " +
- clusterName);
- }
-
-
- // Check cluster address
- String clusterAddress = clusterMBean.getClusterAddress();
- boolean clusterAddressResolved = true;
- if (clusterAddress != null) {
- int nodeNumber = 0;
- String[] nodeAddress = weblogic.utils.StringUtils.splitCompletely(
- clusterAddress, ",", false);
- char delimiter = (char) (new String(":")).charAt(0);
- try {
- if (nodeAddress.length>1) {
- // Honor comma seperated ip list for cluster address.
- // This is allowed only for Development mode.
- while(nodeNumber<nodeAddress.length) {
- // handle port number at the end
- String nodeNameOrAddress = weblogic.utils.StringUtils.upto(
- nodeAddress[nodeNumber],delimiter);
-
- InetAddress.getByName(nodeNameOrAddress);
- nodeNumber++;
- }
- } else {
- // We are in production mode.
- // We should have a DNS entry properly setup
- InetAddress.getByName(clusterAddress);
- }
- weblogic.rjvm.JVMID.localID().setClusterAddress(clusterAddress);
- } catch (UnknownHostException e) {
- if (nodeAddress.length>1) {
- ClusterLogger.logCannotResolveClusterAddressWarning(
- clusterAddress+": Unknown host: "+nodeAddress[nodeNumber]);
- } else {
- ClusterLogger.logCannotResolveClusterAddressWarning(
- clusterAddress);
- }
- }
- }
- // Check the license and if OK, initialize everything
- try {
- checkProcess();
- // Set up the local attributes. If any of these values ever
- // change, stuff them into the localAttributes object and call
- // AttributeManager.theOne().sendAttributes(localAttributes).
- // The code is in place to carry the object to the other
- // cluster members and fire ClusterMembersChangeEvent.UPDATE.
- // A few tasks remain before this will be useful however.
- // 1) There is no machinery in place to notify consumers of
- // localAttributes on the *local* server.
- // 2) ClusterMembersListeners on the remote servers may
- // not have code to respond to UPDATE events.
- // 3) The code has not been tested.
- localAttributes = new MemberAttributes(
- (JVMID) RMIRuntime.getLocalHostID(), serverMBean.getName(),
- serverMBean.getListenAddress(), machineName,
- VersionInfo.theOne().getReleaseVersion(), System.currentTimeMillis(),
- serverMBean.getClusterWeight(),
- serverMBean.getReplicationGroup(),
- serverMBean.getPreferredSecondaryGroup(),
- Admin.getInstance().getActiveDomain().getName(),
- clusterName);
-
- MulticastManager.initialize(
- clusterMBean.getMulticastAddress(),
- Server.getConfig().getInterfaceAddress(),
- clusterMBean.getMulticastPort(),
- (byte)clusterMBean.getMulticastTTL(),
- clusterMBean.getMulticastSendDelay()
- );
-
- // Initialize the managers and the cluster runtime MBean.
- AnnouncementManager.initialize(
- clusterMBean.getServiceAgeThresholdSeconds()
- );
- MemberManager.initialize(localAttributes.joinTime());
- AttributeManager.initialize(localAttributes);
- ReplicationManager.initialize(
- machineName,
- serverMBean.getReplicationGroup(),
- serverMBean.getPreferredSecondaryGroup()
- );
- ClusterRuntime.initialize(Server.getConfig().getName(), clusterName);
- // We use only one thread to ensure ordered processing
- Kernel.addExecuteQueue(MULTICAST_QUEUE, 1);
- isServerInCluster = true;
- } catch (com.bea.utils.misc.ProcessException le) {
- ClusterLogger.logNoClusterLicenseError(le);
- throw new ServerLifecycleException(le.getMessage());
- } catch (IOException ioe) {
- ClusterLogger.logFailedToJoinClusterError(
- clusterName, clusterMBean.getMulticastAddress(), ioe);
- throw new ServerLifecycleException(ioe);
- }
- }
- }
- public void prepareToSuspend()
- throws ServerLifecycleException
- {
- }
- public void forceSuspend() throws ServerLifecycleException {
- if (isServerInCluster)
- MulticastManager.theOne().forceSuspend();
- }
- public void resume() throws ServerLifecycleException {
- if (isServerInCluster)
- MulticastManager.theOne().resume();
- }
- public void shutdown() throws ServerLifecycleException
- {
- if (clusterMBean != null) {
- MemberManager.theOne().shutdown();
- AnnouncementManager.theOne().shutdown();
- }
- }
-
- ///////////////////////////////////
- // For ClusterServices Interface //
- ///////////////////////////////////
- /** Returns null if the server is either not configured to run in a
- * cluster or the cluster mechanisms could not be started.
- * The cluster mechanisms are considered started for this purpose
- * if this service was initialized successfuly.
- */
- public static ClusterServices getServices() {
- if (isServerInCluster)
- return getClusterService();
- else
- return null;
- }
- /* package */ MulticastSession createMulticastSession(int senderID,
- RecoverListener listener,
- int cacheSize,
- boolean useHTTPForStateDumps) {
- return MulticastManager.theOne().createSender(senderID, listener, cacheSize, useHTTPForStateDumps);
- }
- public MulticastSession createMulticastSession(RecoverListener listener,
- int cacheSize, boolean useHTTPForStateDumps) {
- return createMulticastSession(-1, listener, cacheSize, useHTTPForStateDumps);
- }
- public ClusterMemberInfo getLocalMember() {
- return localAttributes;
- }
- public Collection getRemoteMembers() {
- return MemberManager.theOne().getRemoteMembers();
- }
- public void addClusterMembersListener(ClusterMembersChangeListener listener) {
- MemberManager.theOne().addClusterMembersListener(listener);
- }
- public void removeClusterMembersListener(ClusterMembersChangeListener listener) {
- MemberManager.theOne().removeClusterMembersListener(listener);
- }
- public void addHeartbeatMessage(GroupMessage message)
- {
- MulticastManager.theOne().addItem(message);
- }
- public void removeHeartbeatMessage(GroupMessage message)
- {
- MulticastManager.theOne().removeItem(message);
- }
- // check license
- private static boolean l_did = false;
- private void checkProcess() throws com.bea.utils.misc.ProcessException {
- if (!l_did) {
- String l_comp = "Cluster";
- com.bea.utils.misc.Process l_lic;
- java.util.Properties l_prop = new java.util.Properties();
- l_prop.put("product", weblogic.version.getPLInfo()[0]);
- l_prop.put("release", weblogic.version.getPLInfo()[1]);
- l_prop.put("component", l_comp);
- l_prop.put("ip", "");
- try {
- l_lic = com.bea.utils.misc.ProcessManager.memCheck(l_prop);
- formatter.startingClusterService();
- } catch (com.bea.utils.misc.ProcessException l_ex) {
- System.err.println("\n\n$$$$$$$$$$$$$$$$ \u004c\u0069\u0063\u0065\u006e\u0073\u0065 \u0045\u0078\u0063\u0065\u0070\u0074\u0069\u006f\u006e $$$$$$$$$$$$$$$$\n\n");
- System.err.println("Unable to start Cluster Service!");
- System.err.println(l_ex.getMessage());
- System.err.println("\n\n$$$$$$$$$$$$$$$$ \u004c\u0069\u0063\u0065\u006e\u0073\u0065 \u0045\u0078\u0063\u0065\u0070\u0074\u0069\u006f\u006e $$$$$$$$$$$$$$$$\n\n");
- throw l_ex;
- } finally {
- l_did = true;
- }
- }
- }
- }
复制代码 里面大家可以看到原始的WebLogic Inc.的标记,这其实也符合历史事实;因为WebLogic最早也是BEA买来的,那个时候产品不叫WebLogic,被并购的公司叫WebLogic- *
- * @author Copyright (c) 1996-98 by WebLogic, Inc. All Rights Reserved.
- * @author Copyright (c) 1999-2000 by BEA WebXpress. All Rights Reserved.
- */
复制代码 另外,象最后一段是校验License的逻辑,意味着最早的WebLogic中,要是想跑Cluster的话,是需要单独额外的License字段授权的。
这个方面我们就先到这里吧,敏感话题,以后不再碰和涉及;不过一定还会经常回来 
|
|