ChannelRegistry.java
上传用户:psq1974
上传日期:2007-01-06
资源大小:1195k
文件大小:4k
- /* Copyright (C) 1998, 1999 State University of New York at Stony Brook
- Author: Andrew V. Shuvalov ( andrew@ecsl.cs.sunysb.edu )
- Software license is located in file "COPYING"
- VideoServer application
- $Id: ChannelRegistry.java,v 1.6 1999/03/01 03:01:10 andrew Exp $
- */
- package edu.sunysb.cs.ecsl.videoserver;
- import java.io.*;
- import java.util.Hashtable;
- import java.util.Enumeration;
- import java.util.Vector;
- import java.util.Dictionary;
- import java.util.Hashtable;
- /** main parent class should hold the single instance of this class
- */
- class ChannelRegistry
- {
- protected VideoServer parentThread = null;
- /** vector of channels
- */
- private Hashtable channels = new Hashtable();
- /** specify the port range as well */
- ChannelRegistry( VideoServer parent )
- {
- parentThread = parent;
- }
- /**
- */
- protected synchronized void addNewChannel( VideoServerThread ch_thread,
- int id )
- {
- // use the next ID in sequence
- channels.put( new Integer( id ),
- new ChannelRegistryItem( ch_thread ) );
- }
- /** returns the number of channels to list and then 4 lines per channel:
- Id number, port, description and status (active/inactive). Do not leave
- description field blanc! This method also check for each channel to be
- valid at this time; if channel have problems reply with inactive;
- delete channel from list if it's dead.
- Algorithm: first find all push servers that broadcasts to that dest_ip,
- then find the channel for each push server. It is legal (but stupid)
- to have the same channel to be broadcasted to the same LAN by different
- push servers
- */
- protected synchronized void listChannels( DataOutputStream outputstream,
- String dest_ip )
- throws IOException
- {
- // get the list of push servers
- Vector push_ids = parentThread.properties.list_push_serv_ids_by_IP
- ( dest_ip );
- // all push servers will be listed, but some will be reported "inactive"
- outputstream.writeBytes( push_ids.size() + "n" );
- parentThread.log( 2, "report " + push_ids.size() + " channels for " +
- "the address " + dest_ip );
- for(int i = 0; i < push_ids.size(); i++ )
- {
- Dictionary push_info = (Dictionary)push_ids.elementAt( i );
- String push_id = (String)push_info.get( "id" );
- String channel_id = parentThread.properties.getProperty
- ( parentThread.properties.PushServN_AcqServer + push_id );
- // output channel id
- outputstream.writeBytes( channel_id + "n" );
- // output channel port
- String push_port = (String)push_info.get( "port" );
- outputstream.writeBytes( push_port + "n" );
-
- // output channel description ( not empty )
- ChannelRegistryItem ci = (ChannelRegistryItem) channels.get
- ( Integer.valueOf( push_id ) );
- // "hot" description has the priority
- if( ci == null || ci.description == null ||
- ci.description.trim().length() == 0 )
- {
- // try description from system setup
- String descr = parentThread.properties.getProperty
- ( parentThread.properties.AcquisitionServerN_DefDescr +
- channel_id );
- if( descr == null || descr.trim().length() == 0 )
- outputstream.writeBytes( "Channel #" + channel_id + "n" );
- else
- outputstream.writeBytes( descr + "n" );
- }
- else
- outputstream.writeBytes( ci.description + "n" );
- // how to determine status?
- // if this channel does not exists in channel registry - it is
- // inactive
- String active = null;
- if( ci == null )
- active = "inactive";
- else
- active = "active";
- outputstream.writeBytes( active + "n" );
- parentThread.log( 2, "report channel " + channel_id+" "+push_port
- + ", " + active );
- }
- }
- /** if this is a valid channel - remove it. No exceptions - stay silent
- if fail */
- protected synchronized void removeChannel( int Id )
- {
- channels.remove( new Integer( Id ));
- }
- }
- class ChannelRegistryItem
- {
- protected String description = null;
- VideoServerThread channelThread;
- protected ChannelRegistryItem( VideoServerThread ch_thread )
- {
- channelThread = ch_thread;
- }
- }