10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7298SMark.J.Nelson@Sun.COM * Common Development and Distribution License (the "License"). 6*7298SMark.J.Nelson@Sun.COM * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 220Sstevel@tonic-gate * Copyright (c) 2001 by Sun Microsystems, Inc. 230Sstevel@tonic-gate * All rights reserved. 240Sstevel@tonic-gate * 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate // ClientMsgManager.java:Manages versioned client message creation in server 280Sstevel@tonic-gate // Author: James Kempf 290Sstevel@tonic-gate // Created On: Thu Sep 17 10:16:33 1998 300Sstevel@tonic-gate // Last Modified By: James Kempf 310Sstevel@tonic-gate // Last Modified On: Tue Oct 13 15:26:16 1998 320Sstevel@tonic-gate // Update Count: 8 330Sstevel@tonic-gate // 340Sstevel@tonic-gate 350Sstevel@tonic-gate package com.sun.slp; 360Sstevel@tonic-gate 370Sstevel@tonic-gate import java.util.*; 380Sstevel@tonic-gate 390Sstevel@tonic-gate /** 400Sstevel@tonic-gate * The ClientMsgManager class manages creation of client messages in the 410Sstevel@tonic-gate * slpd server. Client messages are needed for active DA advertisement 420Sstevel@tonic-gate * solicitation, and for forwarding of registrations and deregistrations 430Sstevel@tonic-gate * from the SA server to DAs. This class creates the appropriately 440Sstevel@tonic-gate * versioned message instance, based on the arguments. It also 450Sstevel@tonic-gate * sets the header variables. It is up to the caller to set the 460Sstevel@tonic-gate * instance variables in the object itself. 470Sstevel@tonic-gate * 480Sstevel@tonic-gate * @author James Kempf 490Sstevel@tonic-gate */ 500Sstevel@tonic-gate 510Sstevel@tonic-gate abstract class ClientMsgManager extends Object { 520Sstevel@tonic-gate 530Sstevel@tonic-gate // The class table contains classes registered for particular versions 540Sstevel@tonic-gate // and message types. 550Sstevel@tonic-gate 560Sstevel@tonic-gate private static Hashtable classTable = new Hashtable(); 570Sstevel@tonic-gate 580Sstevel@tonic-gate // Register a new message type class and version. 590Sstevel@tonic-gate addClientMsgClass(String className, int version, String keyName)600Sstevel@tonic-gate static void addClientMsgClass(String className, 610Sstevel@tonic-gate int version, 620Sstevel@tonic-gate String keyName) { 630Sstevel@tonic-gate 640Sstevel@tonic-gate // Create the key. 650Sstevel@tonic-gate 660Sstevel@tonic-gate String key = makeClassKey(keyName, version); 670Sstevel@tonic-gate 680Sstevel@tonic-gate try { 690Sstevel@tonic-gate 700Sstevel@tonic-gate Class headerClass = Class.forName(className); 710Sstevel@tonic-gate 720Sstevel@tonic-gate classTable.put(headerClass, key); 730Sstevel@tonic-gate 740Sstevel@tonic-gate } catch (ClassNotFoundException ex) { 750Sstevel@tonic-gate 760Sstevel@tonic-gate Assert.slpassert(false, 770Sstevel@tonic-gate "no_class", 780Sstevel@tonic-gate new Object[] {className}); 790Sstevel@tonic-gate 800Sstevel@tonic-gate } 810Sstevel@tonic-gate } 820Sstevel@tonic-gate 830Sstevel@tonic-gate // Return the appropriately versioned object, with instance variables 840Sstevel@tonic-gate // set in the header. 850Sstevel@tonic-gate 860Sstevel@tonic-gate static SrvLocMsg newInstance(String keyName, int version, boolean isTCP)870Sstevel@tonic-gate newInstance(String keyName, 880Sstevel@tonic-gate int version, 890Sstevel@tonic-gate boolean isTCP) 900Sstevel@tonic-gate throws ServiceLocationException { 910Sstevel@tonic-gate 920Sstevel@tonic-gate try { 930Sstevel@tonic-gate 940Sstevel@tonic-gate // Get header class. 950Sstevel@tonic-gate 960Sstevel@tonic-gate Class msgClass = 970Sstevel@tonic-gate (Class)classTable.get(makeClassKey(keyName, version)); 980Sstevel@tonic-gate 990Sstevel@tonic-gate if (msgClass == null) { 1000Sstevel@tonic-gate throw 1010Sstevel@tonic-gate new ServiceLocationException( 1020Sstevel@tonic-gate ServiceLocationException.INTERNAL_ERROR, 1030Sstevel@tonic-gate "cmm_creation_error", 1040Sstevel@tonic-gate new Object[] { keyName, 1050Sstevel@tonic-gate new Integer(version)}); 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate } 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate SrvLocMsg msg = (SrvLocMsg)msgClass.newInstance(); 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate // Set the packet length. If we've come via TCP, we don't 1120Sstevel@tonic-gate // need to set it. 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate SrvLocHeader hdr = msg.getHeader(); 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate if (!isTCP) { 1170Sstevel@tonic-gate hdr.packetLength = SLPConfig.getSLPConfig().getMTU(); 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate } 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate return msg; 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate } catch (Exception ex) { 1240Sstevel@tonic-gate throw 1250Sstevel@tonic-gate new ServiceLocationException( 1260Sstevel@tonic-gate ServiceLocationException.INTERNAL_ERROR, 1270Sstevel@tonic-gate "cmm_creation_exception", 1280Sstevel@tonic-gate new Object[] { ex, 1290Sstevel@tonic-gate keyName, 1300Sstevel@tonic-gate new Integer(version), 1310Sstevel@tonic-gate ex.getMessage()}); 1320Sstevel@tonic-gate } 1330Sstevel@tonic-gate } 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate // Create the key for the hashtable. 1360Sstevel@tonic-gate makeClassKey(String className, int version)1370Sstevel@tonic-gate private static String makeClassKey(String className, int version) { 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate return className + version; 1400Sstevel@tonic-gate } 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate } 143