📄 muxprovider.java
字号:
rp.reportCallsOnAddress(address, flag);
// no exception - store rp
this.getAddToMap().put(address, rp);
} catch (InvalidArgumentException iae) {
// eat this one and try next
}
}
// didn't find any to handle the address
throw new InvalidArgumentException("No muxed providers handle address: " + address);
}
}
/**
* Delegate off to the appropriate subprovider
*/
public void reportCallsOnTerminal(String terminal, boolean flag) throws ResourceUnavailableException, InvalidArgumentException {
TelephonyProvider rp = this.getTerminalSub(terminal);
if (rp != null) {
if (((RawCapabilities)this.getSubToCaps().get(rp)).throttle)
rp.reportCallsOnTerminal(terminal, flag);
} else {
// poll each raw provider - should never do this since all terminals should have been recorded.
Iterator it = this.getSubProviders().iterator();
while (it.hasNext()) {
try {
rp = (TelephonyProvider)it.next();
rp.reportCallsOnAddress(terminal, flag);
// no exception - store rp
this.getTermToMap().put(terminal, rp);
} catch (InvalidArgumentException iae) {
// eat this one and try next
}
}
// didn't find any to handle the address
throw new InvalidArgumentException("No muxed providers handle terminal: " + terminal);
}
}
/**
* Reserve a call id on the remote server.
*/
public CallId reserveCallId(String address) throws InvalidArgumentException {
TelephonyProvider rp = this.getAddressSub(address);
CallId id = null;
if (rp != null) {
id = rp.reserveCallId(address);
} else { // broadcast - we shouldn't see an Address that we haven't already recorded
boolean found = false;
Iterator it = this.getSubProviders().iterator();
while (it.hasNext() && !found) {
try {
rp = (TelephonyProvider)it.next();
id = rp.reserveCallId(address);
found = true;
} catch (InvalidArgumentException iae) {
// eat and move on to next provider
}
}
if (!found)
throw new InvalidArgumentException("No muxed subproviders know this Address: " + address);
}
if (id != null) {
// map the call id in our local table
return this.registerCall(id, rp);
} else
return null;
}
/**
* Delegate off to the appropriate subprovider
*/
public RawSigDetectEvent retrieveSignals(String terminal, int num, Symbol[] patterns, RTC[] rtcs, Dictionary optArgs) throws MediaResourceException {
return this.getTerminalSub(terminal).retrieveSignals(terminal, num, patterns, rtcs, optArgs);
}
/**
* Find the sub-provider to forward the sendPrivateData call to, and forward it.
*/
public Object sendPrivateData(CallId call, String address, String terminal, Object data) {
TelephonyProvider tp = null; // used for unicast messages
CallId newCallId = null;
Iterator it = null; // used of broadcast messages
// 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().sendPrivateData(ch.getCall(), address, terminal, data);
if (o != null)
set.add(o);
}
return set.toArray();
}
} else if (address != null) {
// check if the address will now do it
tp = this.getAddressSub(address);
} else if (terminal != null) {
// check if only the terminal will id it.
tp = this.getTerminalSub(terminal);
} else {
// all providers are required
Set set = new HashSet();
it = this.getSubProviders().iterator();
while (it.hasNext()) {
Object o = ((TelephonyProvider)it.next()).sendPrivateData(null, null, null, data);
if (o != null)
set.add(o);
}
return set.toArray();
}
// one provider found
if (tp != null) {
return tp.sendPrivateData(newCallId, address, terminal, data);
}
// no providers found
return null;
}
/**
* Delegate off to the appropriate subprovider
*/
public void sendSignals(String terminal, Symbol[] syms, RTC[] rtcs, Dictionary optArgs) throws MediaResourceException {
this.getTerminalSub(terminal).sendSignals(terminal, syms, rtcs, optArgs);
}
/**
* We assume that the providers are at both ends of the range
*/
public void setLoadControl(java.lang.String startAddr, java.lang.String endAddr, double duration, double admissionRate, double interval, int[] treatment) throws javax.telephony.MethodNotSupportedException {
if (startAddr != null) {
this.getAddressSub(startAddr).setLoadControl(startAddr, endAddr, duration, admissionRate, interval, treatment);
}
if ((endAddr != null) && (!startAddr.equals(endAddr))) {
this.getAddressSub(startAddr).setLoadControl(startAddr, endAddr, duration, admissionRate, interval, treatment);
}
}
/**
* Find the sub-provider to forward the setPrivateData call to, and forward it.
*/
public void setPrivateData(CallId call, String address, String terminal, Object data) {
TelephonyProvider tp = null; // used for unicast messages
CallId newCallId = null;
Iterator it = null; // used for broadcast messages
// 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();
while (it.hasNext()) {
CallHolder ch = (CallHolder)it.next();
ch.getTpi().setPrivateData(ch.getCall(), address, terminal, data);
}
}
} else if (address != null) {
// check if the address will now do it
tp = this.getAddressSub(address);
} else if (terminal != null) {
// check if only the terminal will id it.
tp = this.getTerminalSub(terminal);
} else {
// all providers are required
it = this.getSubProviders().iterator();
while (it.hasNext()) {
((TelephonyProvider)it.next()).setPrivateData(null, null, null, data);
}
}
// one provider found
if (tp != null) {
tp.setPrivateData(newCallId, address, terminal, data);
}
}
/**
* Tell the remote provider to shutdown. It may choose to ignore me.
*/
public void shutdown() {
Iterator it = this.getSubProviders().iterator();
while (it.hasNext()) {
((TelephonyProvider)it.next()).shutdown();
}
}
/**
* Pass on the stop media request to the correct sub-provider
*/
public void stop(String terminal) {
this.getTerminalSub(terminal).stop(terminal);
}
/**
* Delegate off to the appropriate sub-provider
*/
public boolean stopReportingCall(CallId call) {
Iterator it = ((MuxCallId)call).getCallHolders();
boolean result = true; // assume that they all will unless one declines
while (it.hasNext()) {
CallHolder ch = (CallHolder)it.next();
result = result && ch.getTpi().stopReportingCall(ch.getCall());
}
return result;
}
/**
* Describe myself
* @return a string representation of the receiver
*/
public String toString() {
StringBuffer sb = new StringBuffer("Raw Multiplexor Provider managing: ");
Iterator it = this.getSubProviders().iterator();
while (it.hasNext()) {
TelephonyProvider rp = (TelephonyProvider)it.next();
sb.append(" ").append(rp.toString());
}
return sb.toString();
}
/**
* This method assists in knitting call legs together that exist in two sub-providers
* but that represent parts of one logical call.
* Creation date: (2000-09-27 15:49:07)
* @return net.sourceforge.gjtapi.CallData
* @param muxCall The mux virtual call that holds all sub-call holders.
* @param from The address set the call leg comes from. Used to help distinguish multiple calls at the destination.
* @param to The address where the call leg should be.
* @param state the Connection state of the call leg. Used to help distinguish leg that both come from the same source.
* @param addressSet The set of currently found locally-resolved addresses. Used to stop cyclical recursion.
*/
private CallData traceCall(MuxCallId muxCall, String[] from, String to, int state, HashSet addressSet) {
CallData found = null;
int fromSize = from.length;
// find the sub-provider and ask it for all calls on the address
TelephonyProvider prov = this.getAddressSub(to);
if (prov != null) {
CallData[] subCalls = prov.getCallsOnAddress(to);
int size = subCalls.length;
// look at all sub-calls
for (int i = 0; i < size; i++) {
CallData cd = subCalls[i];
int connSize = cd.connections.length;
for (int j = 0; j < connSize; j++) {
ConnectionData conn = cd.connections[j];
for (int k = 0; k < fromSize; k++) {
if ((conn.address.equals(from[k])) && (conn.connState == state)) {
if (found == null) {
found = cd;
break; // don't check any more connections
} else {
// two possible calls -- return null to indicate failure
return null;
}
}
}
if (found != null)
break; // break out of connections
}
}
// now we need to check if we should shut off reporting for the other returned Calls
boolean shutOff = false;
for (int i = 0; (i < size) && (!shutOff); i++) {
CallData cd = subCalls[i];
CallId subCallId = cd.id;
if ((!cd.equals(found)) && (this.findCall(subCallId, prov) == null)) {
prov.stopReportingCall(subCallId);
shutOff = true;
}
}
// If we turned any call reporting off, we need to turn call reporting off for
// future calls on this address
if (shutOff) {
// only catch non-Runtime exceptions -- we want others to blow things up
Exception e = null;
try {
prov.reportCallsOnAddress(to, false);
prov.getCall(found.id); // to ensure this is still being reported
} catch (InvalidArgumentException iae) {
e = iae;
} catch (ResourceUnavailableException rue) {
e = rue;
}
if (e != null) {
System.out.println("Internal logic error during multiplexor call tracing:");
e.printStackTrace();
}
}
if (found != null) {
// Add the new local addresses to the addressSet
ConnectionData[] connData = found.connections;
int cdSize = connData.length;
for (int i = 0; i < cdSize; i++) {
if (connData[i].isLocal) {
addressSet.add(connData[i].address);
}
}
// Create and add a new CallHolder if needed
if (muxCall.getLeg(to) == null) {
muxCall.addCall(found.id, prov);
// update the address and terminal mapping
for (int i = 0; i < cdSize; i++) {
this.mapConnection(connData[i], prov);
}
}
// finally, recursively merge in any other bridged connections
found = this.merge(found, this.traceCalls(muxCall,
connData,
addressSet));
}
}
return found;
}
/**
* This method assists in knitting call legs together that exist in two sub-providers by merging all remote connections in the logical mux call.
* Only remote addresses not yet recorded in addressSet are followed.
* but that represent parts of one logical call.
* Creation date: (2000-09-27 15:49:07)
* @return net.sourceforge.gjtapi.CallData
* @param muxCall The mux virtual call that holds all sub-call holders.
* @param addressSet The set of currently found locally-resolved addresses. Used to stop cyclical recursion.
*/
private CallData traceCalls(MuxCallId muxCall, ConnectionData[] conns, HashSet addressSet) {
CallData found = null;
int cdSize = conns.length;
// finally, recursively merge in any other bridged connections
for (int i = 0; i < cdSize; i++) {
if (!conns[i].isLocal) {
ConnectionData conn = conns[i];
// ensure we don't get in a recursive loop
if (!addressSet.contains(conn.address))
found = this.merge(found, this.traceCall(muxCall,
found.getLocalAddresses(),
conn.address,
conn.connState,
addressSet));
}
}
return found;
}
/**
* Pas on the triggerRTC method to the correct sub-provider.
*/
public void triggerRTC(String terminal, Symbol action) {
this.getTerminalSub(terminal).triggerRTC(terminal, action);
}
/**
* Tell the remote provider to unhold a terminal from a call
*/
public void unHold(CallId call, String address, String term) throws RawStateException, MethodNotSupportedException,
PrivilegeViolationException, ResourceUnavailableException {
CallHolder ch = this.getSub(call, address);
if (ch != null) {
ch.getTpi().unHold(ch.getCall(), address, term);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -