⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 muxprovider.java

📁 jtapi for telephone
💻 JAVA
📖 第 1 页 / 共 4 页
字号:

	// Merge the set of morphed sub-calls
	CallData mergedCall = null;
	int size = connections.size();
	if (size > 0) {
		mergedCall = new CallData(id, state, (ConnectionData[])connections.values().toArray(new ConnectionData[size]));
	}
	
	// now return the set
	return mergedCall;
}
/**
 * Internal accessor for the set of logical calls I'm handling.
 * Creation date: (2000-02-22 16:06:01)
 * @author: Richard Deadman
 * @return The set of logical calls that may be bridged across more than 1 sub-provider calls.
 */
private Set getCalls() {
	return calls;
}
/**
 * Get a set of CallData snapshots for all calls that are attached to an address.
 * This will follow logical links to call legs in other sub-providers.
 */
public CallData[] getCallsOnAddress(String number) {
	TelephonyProvider sub = this.getAddressSub(number);
	if (sub != null) {
		CallData[] cd = sub.getCallsOnAddress(number);
	
		// now map these calls to the sub-provider
		if (cd != null) {
			int cdSize = cd.length;
			for (int i = 0; i < cdSize; i++) {	// for each found call
				CallData call = cd[i];
					// lazily create the logical call
				MuxCallId callId = this.noteCall(call.id, sub);
					// trace the call to other providers and store back in our array
				cd[i] = this.merge(call, this.traceCalls(callId, call.connections, new HashSet()));
					// record the sub-parts
				this.mapCall(callId, call, sub);
			}
				// return the traced calls
			return cd;
		}
	}

	// We found no calls
	return null;
}
/**
 * Get a set of CallData snapshots for all calls that are attached to a Terminal.
 * This will follow logical links to call legs in other sub-providers.
 */
public CallData[] getCallsOnTerminal(String name) {
	TelephonyProvider sub = this.getTerminalSub(name);
	if (sub != null) {
		CallData[] cd = sub.getCallsOnTerminal(name);
	
		// now map these calls to the sub-provider
		if (cd != null) {
			int cdSize = cd.length;
			for (int i = 0; i < cdSize; i++) {	// for each found call
				CallData call = cd[i];
					// lazily create the logical call
				MuxCallId callId = this.noteCall(call.id, sub);
					// trace the call to other providers and store back in our array
				cd[i] = this.merge(call, this.traceCalls(callId, call.connections, new HashSet()));
					// record the sub-parts
				this.mapCall(callId, call, sub);
			}
				// return the traced calls
			return cd;
		}
	}

	// We found no calls
	return null;
}
/**
 * Create the lowest common denominator of capabilities and return it.
 */
public java.util.Properties getCapabilities() {
	Properties merged = new Properties();

	// load the set of capabilities
	Iterator subs = this.getSubToCaps().values().iterator();
	while (subs.hasNext()) {
		Properties subProps = ((Properties)subs.next());

		if (subProps != null) {
			// test each capability
			Iterator keys = subProps.keySet().iterator();
			while (keys.hasNext()) {
				Object key = keys.next();
				Object val = null;
				if (key.equals(Capabilities.THROTTLE) || key.equals(Capabilities.MEDIA) ||
					key.equals(Capabilities.ALLOCATE_MEDIA) || key.equals(Capabilities.DYNAMIC_ADDRESSES) ||
					((key instanceof String) && (((String)key).endsWith(Capabilities.PD))))
					val = this.gcd(merged.get(key), subProps.get(key));
				else
					val = this.lcd(merged.get(key), subProps.get(key));
				merged.put(key, val);
			}
		}
	}
	return merged;
}
/**
 * getDialledDigits method comment.
 */
public java.lang.String getDialledDigits(net.sourceforge.gjtapi.CallId id, java.lang.String address) {
	CallHolder ch = ((MuxCallId)id).getLeg(address);
	if (ch != null) {
		return ch.getTpi().getDialledDigits(ch.getCall(), address);
	} else
		return null;
}
/**
 * Insert the method's description here.
 * Creation date: (2000-09-25 16:27:57)
 * @return java.util.Map
 */
private java.util.Map getLowToLogicalMap() {
	return lowToLogicalMap;
}
/**
 * Find the sub-provider to forward the getPrivateData call to, and forward it.
 */
public Object getPrivateData(CallId call, String address, String terminal) {
	TelephonyProvider tp = null;	// if single sub-provider identified
	CallId newCallId = null;
	Iterator it = null;				// if call bridges sub-providers, or broadcast required
		// check if call ids the provider
	if (call != null) {
		if  (address != null) {		// Connection of TerminalConnection
			CallHolder ch = this.getSub(call, address);
			tp = ch.getTpi();
			newCallId = ch.getCall();
		} else {					// Broadcast to all multiplexed Calls
			it = ((MuxCallId)call).getCallHolders();
			Set set = new HashSet();
			while (it.hasNext()) {
				CallHolder ch = (CallHolder)it.next();
				Object o = ch.getTpi().getPrivateData(ch.getCall(), address, terminal);
				if (o != null)
					set.add(o);
			}
			return set.toArray();
		}
	} else if (address != null) {	// Call is null - just Address defined
		// check if the address will now do it
		tp = this.getAddressSub(address);
	} else if (terminal != null) {	// Call is null - just Terminal defined
		// check if only the terminal will id it.
		tp = this.getTerminalSub(terminal);
	} else {						// all null - Provider broadcast
		// all providers are required
		Set set = new HashSet();
		it = this.getSubProviders().iterator();
		while (it.hasNext()) {
			Object o = ((TelephonyProvider)it.next()).getPrivateData(call, address, terminal);
			if (o != null)
				set.add(o);
		}
		return set.toArray();
	}

		// one provider found
	if (tp != null) {
		return tp.getPrivateData(newCallId, address, terminal);
	}

		// no providers found
	return null;
}
/**
 * Get the sub-provider for a logical call that is handling a particular address.
 * This allows a call being bridged across multiple sub-providers to find the correct sub-provider.
 * Creation date: (2000-03-09 12:26:30)
 * @author: Richard Deadman
 * @return The subprovider that handles the call's address
 * @param id A call id to find a subprovider for
 * @paran address An address that identifies a call-leg handled by one of the sub-providers.
 */
private CallHolder getSub(CallId id, String address) {
	return ((MuxCallId)id).getLeg(address);
}
/**
 * Internal accessor.
 * Creation date: (2000-02-22 15:37:42)
 * @author: Ricahrd Deadman
 * @return The set of RawProviders I delegate to.
 */
private Set getSubProviders() {
	return this.getSubToCaps().keySet();
}
/**
 * Internal accessor
 * Creation date: (2000-02-22 16:06:01)
 * @author: Richard Deadman
 * @return The Sub-provider to RawCapabilites map.
 */
private Map getSubToCaps() {
	return subToCaps;
}
/**
 * Return the static set of terminals I manage, using lazy instantiation.
 * Creation date: (2000-02-22 15:32:00)
 * @author: Richard Deadman
 * @return The set of know addresses I manage
 */
public TermData[] getTerminals() throws ResourceUnavailableException {
	Map termMap = this.getTermToMap();
	HashSet tdSet = this.termData;

		// test if we need to flush the addresses in
	if (this.termFlag == MuxProvider.UNFLUSHED) {
		synchronized (tdSet) {
			if (this.termFlag == MuxProvider.UNFLUSHED) {	// double check
					// ask each sub-provider
				Iterator it = this.getSubProviders().iterator();
				while (it.hasNext()) {
					TelephonyProvider sub = (TelephonyProvider)it.next();
					TermData[] subTerms = null;
					try {
						subTerms = sub.getTerminals();
					} catch (ResourceUnavailableException rue) {
						this.termFlag = MuxProvider.TOOBIG;	// mark as not all available
						tdSet.clear();			// might as well clear the TermData holder
						this.termData = null;
						break;
					}
					int size = subTerms.length;
					for (int i = 0; i < size; i++) {
						TermData td = subTerms[i];
						tdSet.add(td);
						termMap.put(td.terminal, sub);
					}
				}
				if (this.termFlag == MuxProvider.UNFLUSHED)
					this.termFlag = FLUSHED;
			}
		}
	}
	// now test for too big
	if (this.termFlag == MuxProvider.TOOBIG) {
		throw new ResourceUnavailableException(ResourceUnavailableException.UNKNOWN,
			"Some Sub-TelephonyProviders cannot return all addresses");
	}

		// must now be set to FLUSHED
	return (TermData[])tdSet.toArray(new TermData[0]);
}
/**
 * Return from the remote provider a set of terminal names for an address.
 */
public TermData[] getTerminals(String address) throws InvalidArgumentException {
	TelephonyProvider sub = this.getAddressSub(address);
	TermData[] terms = null;
	if (sub != null) {
		terms = sub.getTerminals(address);
	} else {	// broadcast
		boolean found = false;
		Iterator it = this.getSubProviders().iterator();
		while (it.hasNext() && !found) {
			try {
				sub = (TelephonyProvider)it.next();
				terms = sub.getTerminals(address);
					// didn't throw exception -- success
				found = true;
				this.getAddToMap().put(address, sub);
			} catch (InvalidArgumentException iae) {
				// eat and move on to next provider
			}
		}
		if (!found)
			throw new InvalidArgumentException("No muxed subproviders know this Address: " + address);
	}

	// now map these to the sub-provider
	if (terms != null) {
		Map termMap = this.getTermToMap();
		int size = terms.length;
		for (int i = 0; i < size; i++)
			termMap.put(terms[i].terminal, sub);
	}

	// now return the set
	return terms;
}
/**
 * Get the sub-provider mapped to by a certain Terminal
 * Creation date: (2000-03-09 12:26:30)
 * @author: Richard Deadman
 * @return The subprovider that handles the terminal
 * @param address A terminal name to find a subprovider for
 */
private TelephonyProvider getTerminalSub(String terminal) {
	return (TelephonyProvider)this.getTermToMap().get(terminal);
}
/**
 * Private accessor for terminal map.
 * Creation date: (2000-03-09 10:37:55)
 * @author: Richard Deadman
 * @return The map that maps terminal names to sub-providers.
 */
private java.util.Map getTermToMap() {
	return termToSub;
}
/**
 * Send a hold message for a terminal to a remote provider.
 */
public void hold(CallId call, String address, String term) throws RawStateException, MethodNotSupportedException,
		PrivilegeViolationException, ResourceUnavailableException {
	TelephonyProvider sub = this.getAddressSub(address);
	if (sub != null)
		sub.hold(call, address, term);
}
/**
 * Load my properties and use to look-up my set of sub-providers
 * These properties could be used locally or sent to the server for the creation of a user-session.
 */
public void initialize(Map props) throws ProviderUnavailableException {
	Map m = null;
	Object value = null;
	
	// See if I also need to load the properties file
	boolean replace = false;
	if (props != null) {
		value = props.get("replace");
		replace = net.sourceforge.gjtapi.capabilities.Capabilities.resolve(value);
	}
	if (replace)
		m = props;
	else {
		m = this.loadResources(MuxProvider.RESOURCE_NAME);
		if (props != null)
			m.putAll(props);
	}

	// Now load each sub-provider
	Map addMap = this.getAddToMap();
	Vector addSet = new Vector();
	Map subCaps = this.getSubToCaps();
	
	Iterator it = m.keySet().iterator();
	while (it.hasNext()) {
		String key = (String)it.next();
		if (key.startsWith(MuxProvider.PROVIDER_PREFIX)) {
			String em = (String)m.get(key);
			String cn = (String)m.get(MuxProvider.CLASS_PREFIX+em);
			String propfile = (String)m.get(MuxProvider.PROPS_PREFIX+em);

			// load the sub-provider
			TelephonyProvider rp = null;
			try {
				rp = ProviderFactory.createProvider((CoreTpi)Class.forName(cn).newInstance());
			} catch (Exception ex) {
				throw new ProviderUnavailableException();
			}
			rp.initialize(this.loadResources(propfile));

			// add the provider's RawCapabilities
			subCaps.put(rp, rp.getCapabilities());
		}
	}
}
/**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -