📄 genericmediaservice.java
字号:
if (this.getMediaGroup() == null)
throw new BindCancelledException("Cancelled");
}
}
/*
* Bind this MediaService to a particular Terminal.
* <p>
*
* @param configSpec declares configuration requirments for the MediaGroup.
* @param terminal a JTAPI Terminal object.
*
* @exception MediaBindException one of AlreadyBoundException, BindCancelledException.
* @exception MediaConfigException if MediaGroup can not be configured as requested.
*/
public void bindToTerminal(ConfigSpec configSpec, Terminal terminal) throws MediaBindException, MediaConfigException {
if (this.isBound())
throw new AlreadyBoundException();
this.bindToGroup(new GenericMediaGroup(configSpec, terminal, this));
}
/*
* Bind this MediaService to a particular Terminal.
* <p>
* @param configSpec declares configuration requirments for the MediaGroup
* @param terminalName a String that names a media capable Terminal
* @throws MediaBindException one of AlreadyBoundException, BindCancelledException.
* @throws MediaConfigException if MediaGroup can not be configured as requested
*/
public void bindToTerminalName(ConfigSpec configSpec, String terminalName) throws MediaBindException, MediaConfigException {
Terminal t = null;
try {
t = this.getProvider().getTerminal(terminalName);
} catch (InvalidArgumentException iae) {
throw new ResourceNotSupportedException("No known terminal: " + terminalName);
}
this.bindToTerminal(configSpec, t);
}
/*
* Revoke previous bindToXXXX() request on this MediaService.
* <br>
* This is called from a thread that is NOT blocked in a bind() method,
* and will unblock the bindToXXXX() request.
* <p>
* This method is "one-way" and Listener-safe. The app/Listener will
* receive either a bind completion event or a BindCancelledException as the
* result of the outstanding bindToXXXX().
*/
public void cancelBindRequest() {
synchronized (this) {
this.notifyAll();
}
}
/**
* Checks if a virtual MediaGroup is bound, and returns it.
* If no MediaGroup is bound, throw the RuntimeException NotBoundException.
* <p>
* Applications that subclass BasicMediaService should generally
* <b>not</b> use this directly.
*
* @exception NotBoundException if not currently bound to a MediaGroup
* @return Myself so that the player methods can be forwarded.
*/
private GenericMediaGroup checkGroup() throws NotBoundException {
GenericMediaGroup mg = this.getMediaGroup();
if (mg == null)
throw new NotBoundException();
return mg;
}
/*
* Configure current MediaGroup according to ConfigSpec.
* <p>
* Post-Condition: (foreach R in configSpec {this.isInstanceOf(R)})
* and the Resource is allocated and connected in the MediaGroup.
* <p>
* <b>Note:</b>
* On some implementations this method stops all media operations.
*
* @param configSpec the requested configuration
* @exception NotBoundException if not currently bound to a MediaGroup
* @exception MediaConfigException if resources can not be configured as requested
*/
public void configure(ConfigSpec configSpec)
throws MediaConfigException {
this.checkGroup().allocate(configSpec.getResourceSpecs());
}
/*
* Extract a subset from a dictionary based on a set of Symbol keys.
*
* If the key set is null, create a snapshot
*/
private Dictionary extract(Dictionary dict, Symbol[] keys) {
// take snapshot if keys null
if (keys == null) {
Dictionary snapshot = new Hashtable(dict.size());
Enumeration e = dict.keys();
while (e.hasMoreElements()) {
Object key = e.nextElement();
snapshot.put(key, dict.get(key));
}
return snapshot;
}
// find the matching keys
Dictionary subSet = new Hashtable();
int size = keys.length;
for (int i = 0; i < size; i++) {
if (keys[i] != null) {
Object o = dict.get(keys[i]);
if (o != null)
subSet.put(keys[i], o);
}
}
return subSet;
}
/**
* Called when the object is no longer held onto
* Creation date: (2000-05-24 09:44:08)
* @author: Richard Deadman
*/
public void finalize() {
// release and free the MediaGroup but don't disconnect the connection.
try {
this.releaseAndFree();
} catch (NotBoundException nbe) {
// then we don't need to release
}
}
/* This implementation assumes that the Jtapi Provider
* is a MediaProvider, possibly an unfounded assumption.
* However, it serves to convince the compiler that the
* indicated exceptions may be thrown.
* <P>Note that a a null peer name is okay.
*/
MediaProvider findMediaProvider(String peerName, String providerString)
throws ClassNotFoundException,
InstantiationException,
IllegalAccessException,
ProviderUnavailableException {
return ((MediaProvider)
((JtapiPeer)Class.forName(peerName).newInstance())
.getProvider(providerString));
}
/* @see SignalDetector#flushBuffer() */
public SignalDetectorEvent flushBuffer() throws MediaResourceException {
return this.checkGroup().flushBuffer();
}
/*
* Get current configuration of the MediaGroup.
* <p>
* Note this does not generally return a copy of the ConfigSpec
* used to create/configure this MediaGroup; the returned ConfigSpec
* describes the full and actual configuration of resources.
*
* @return a ConfigSpec describing the current configuration.
* @exception NotBoundException if not currently bound to a MediaGroup
* <p>
*/
public ConfigSpec getConfiguration() throws NotBoundException {
return this.checkGroup().getConfigSpec();
}
/**
* Accessor for an Iterator over bound MediaListeners.
* Creation date: (2000-05-03 15:22:54)
* @author: Richard Deadman
* @return An iterator over MediaListeners attached to me.
*/
public Iterator getListeners() {
return GenericMediaService.theListeners.iterator();
}
/**
* Insert the method's description here.
* Creation date: (2000-03-13 15:04:17)
* @author:
* @return net.sourceforge.gjtapi.media.GenericMediaGroup
*/
private GenericMediaGroup getMediaGroup() {
return mediaGroup;
}
/**
* Cast myself
*/
public MediaService getMediaService() {
return this;
}
/**
* Internal media manager accessor
* Creation date: (2000-03-24 15:52:33)
* @author: Richard Deadman
* @return The media manager that tracks media services against terminals and waiting service names.
*/
private MediaMgr getMgr() {
return mgr;
}
/*
* get a collection of Parameters from the Group/Resources.
*
* @param keys is a Dictionary indicating the paramters of interest.
* The values in this Dictionary are placed with the values of the
* indicated parameter. If a requested parameter is not supported
* by the MediaService implementation, that key is removed from the Dictionary.
* @return Dictionary of values bound to the given keys
*/
public Dictionary getParameters(Symbol[] keys) {
return this.extract(this.checkGroup().getParameters(), keys);
}
/**
* Internal provider accessor
* Creation date: (2000-03-24 15:52:33)
* @author: Richard Deadman
* @return The system provider that manages terminals and raw providers
*/
private net.sourceforge.gjtapi.GenericProvider getProvider() {
return provider;
}
/*
* Get the Jtapi Terminal associated with the MediaService.
* The Terminal may be used to access the associated JTAPI objects.
* <p>
* If this MediaService is not associated with a
* JTAPI call control Provider, this method may return null.
*/
public Terminal getTerminal() {
return checkGroup().getTerminal();
}
/*
* Return the installation specific String that identifies
* the Terminal to which this MediaService is bound.
*
* @return a String that uniquely identifies the bound Terminal.
* @throws NotBoundException if not currently bound to a MediaGroup
* @see #getTerminal
*/
public String getTerminalName() {
Terminal t = this.getTerminal();
if (t == null)
return null;
else
return t.getName();
}
/*
* Creates and returns a new Dictionary object that contains a snapshot of
* the MediaGroup Dictionary.
* <p>
* @return A Dictionary of application-shared information.
* @exception NotBoundException if not currently bound to a MediaGroup
*/
public Dictionary getUserDictionary() throws NotBoundException {
this.checkGroup();
return this.getMediaGroup().getDictionary();
}
/**
* Creates and returns a new Dictionary that contains
* the UserDictionary values corresponding to a given set of keys.
* <p>
* If the keys argument is <code>null</code> then a snapshot of
* the entire UserDictionary is returned.
* <p>
* For interoperability with other languages,
* the keys in the Dictionary are restricted to type Symbol.
* The result of using keys of other types is undefined,
* but throwing a ClassCastException is considered compliant.
* <p>
* @param keys an array of key Symbols
* @return a Dictionary of application-shared information.
*
* @throws NotBoundException if not currently bound to a MediaGroup
*/
public Dictionary getUserValues(Symbol[] keys) throws NotBoundException {
return this.extract(this.checkGroup().getDictionary(), keys);
}
private void initMediaService(MediaProvider provider) {
GenericProvider prov = this.provider = (GenericProvider)provider;
this.mgr = prov.getMediaMgr();
// mark this group as unbound, no bind in progress:
// also tests _provider for null, pings _provider.
this.setMediaGroup(null);
}
/**
* @return true iff this MediaService is bound to a MediaGroup.
*/
public boolean isBound() {
return (this.mediaGroup != null);
}
public void onDisconnected(MediaEvent event) {
EventListener listener;
Iterator iter = theListeners.iterator();
while(iter.hasNext()) {
listener = (EventListener)iter.next();
if(listener instanceof MediaServiceListener) {
try {
((MediaServiceListener)listener).onDisconnected(event);
} catch (Exception ex) {}
}
}
}
/* @see SignalDetectorListener#onOverflow(SignalDetectorEvent) */
public void onOverflow(SignalDetectorEvent signaldetectorevent0)
{
EventListener listener;
Iterator iter = theListeners.iterator();
while(iter.hasNext()) {
listener = (EventListener)iter.next();
if(listener instanceof SignalDetectorListener) {
try {
((SignalDetectorListener)listener).onOverflow(signaldetectorevent0);
} catch (Exception ex) {}
}
}
}
/* @see SignalDetectorListener#onPatternMatched(SignalDetectorEvent) */
public void onPatternMatched(SignalDetectorEvent signaldetectorevent0)
{
EventListener listener;
Iterator iter = theListeners.iterator();
while(iter.hasNext()) {
listener = (EventListener)iter.next();
if(listener instanceof SignalDetectorListener) {
try {
((SignalDetectorListener)listener).onPatternMatched(signaldetectorevent0);
} catch (Exception ex) {}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -