/*
* Copyright 2004-2006 Stefan Reuter
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.asteriskjava.manager.internal;
import static org.asteriskjava.manager.ManagerConnectionState.CONNECTED;
import static org.asteriskjava.manager.ManagerConnectionState.CONNECTING;
import static org.asteriskjava.manager.ManagerConnectionState.DISCONNECTED;
import static org.asteriskjava.manager.ManagerConnectionState.DISCONNECTING;
import static org.asteriskjava.manager.ManagerConnectionState.INITIAL;
import static org.asteriskjava.manager.ManagerConnectionState.RECONNECTING;
import java.io.IOException;
import java.io.Serializable;
import java.net.Socket;
import java.net.InetAddress;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import org.asteriskjava.AsteriskVersion;
import org.asteriskjava.manager.*;
import org.asteriskjava.manager.action.ChallengeAction;
import org.asteriskjava.manager.action.CommandAction;
import org.asteriskjava.manager.action.EventGeneratingAction;
import org.asteriskjava.manager.action.LoginAction;
import org.asteriskjava.manager.action.LogoffAction;
import org.asteriskjava.manager.action.ManagerAction;
import org.asteriskjava.manager.event.ConnectEvent;
import org.asteriskjava.manager.event.DisconnectEvent;
import org.asteriskjava.manager.event.ManagerEvent;
import org.asteriskjava.manager.event.ProtocolIdentifierReceivedEvent;
import org.asteriskjava.manager.event.ResponseEvent;
import org.asteriskjava.manager.response.ChallengeResponse;
import org.asteriskjava.manager.response.CommandResponse;
import org.asteriskjava.manager.response.ManagerError;
import org.asteriskjava.manager.response.ManagerResponse;
import org.asteriskjava.util.DateUtil;
import org.asteriskjava.util.Log;
import org.asteriskjava.util.LogFactory;
import org.asteriskjava.util.SocketConnectionFacade;
import org.asteriskjava.util.internal.SocketConnectionFacadeImpl;
import org.asteriskjava.manager.action.UserEventAction;
/**
* Internal implemention of the ManagerConnection interface.
*
* @author srt
* @version $Id: ManagerConnectionImpl.java 1286 2009-04-04 09:40:40Z srt $
* @see org.asteriskjava.manager.ManagerConnectionFactory
*/
public class ManagerConnectionImpl implements ManagerConnection, Dispatcher
{
private static final int RECONNECTION_INTERVAL_1 = 50;
private static final int RECONNECTION_INTERVAL_2 = 5000;
private static final String DEFAULT_HOSTNAME = "localhost";
private static final int DEFAULT_PORT = 5038;
private static final int RECONNECTION_VERSION_INTERVAL = 500;
private static final int MAX_VERSION_ATTEMPTS = 4;
private static final AtomicLong idCounter = new AtomicLong(0);
/**
* Instance logger.
*/
private final Log logger = LogFactory.getLog(getClass());
private final long id;
/**
* Used to construct the internalActionId.
*/
private AtomicLong actionIdCounter = new AtomicLong(0);
/* Config attributes */
/**
* Hostname of the Asterisk server to connect to.
*/
private String hostname = DEFAULT_HOSTNAME;
/**
* TCP port to connect to.
*/
private int port = DEFAULT_PORT;
/**
* <code>true</code> to use SSL for the connection, <code>false</code>
* for a plain text connection.
*/
private boolean ssl = false;
/**
* The username to use for login as defined in Asterisk's
* <code>manager.conf</code>.
*/
protected String username;
/**
* The password to use for login as defined in Asterisk's
* <code>manager.conf</code>.
*/
protected String password;
/**
* The default timeout to wait for a ManagerResponse after sending a
* ManagerAction.
*/
private long defaultResponseTimeout = 2000;
/**
* The default timeout to wait for the last ResponseEvent after sending an
* EventGeneratingAction.
*/
private long defaultEventTimeout = 5000;
/**
* The timeout to use when connecting the the Asterisk server.
*/
private int socketTimeout = 0;
/**
* Closes the connection (and reconnects) if no input has been read for the given amount
* of milliseconds. A timeout of zero is interpreted as an infinite timeout.
*
* @see Socket#setSoTimeout(int)
*/
private int socketReadTimeout = 0;
/**
* <code>true</code> to continue to reconnect after an authentication failure.
*/
private boolean keepAliveAfterAuthenticationFailure = true;
/**
* The socket to use for TCP/IP communication with Asterisk.
*/
private SocketConnectionFacade socket;
/**
* The thread that runs the reader.
*/
private Thread readerThread;
private final AtomicLong readerThreadCounter = new AtomicLong(0);
private final AtomicLong reconnectThreadCounter = new AtomicLong(0);
/**
* The reader to use to receive events and responses from asterisk.
*/
private ManagerReader reader;
/**
* The writer to use to send actions to asterisk.
*/
private ManagerWriter writer;
/**
* The protocol identifer Asterisk sends on connect wrapped into an object
* to be used as mutex.
*/
private final ProtocolIdentifierWrapper protocolIdentifier;
/**
* The version of the Asterisk server we are connected to.
*/
private AsteriskVersion version;
/**
* Contains the registered handlers that process the ManagerResponses.
* <p/>
* Key is the internalActionId of the Action sent and value the
* corresponding ResponseListener.
*/
private final Map<String, SendActionCallback> responseListeners;
/**
* Contains the event handlers that handle ResponseEvents for the
* sendEventGeneratingAction methods.
* <p/>
* Key is the internalActionId of the Action sent and value the
* corresponding EventHandler.
*/
private final Map<String, ManagerEventListener> responseEventListeners;
/**
* Contains the event handlers that users registered.
*/
private final List<ManagerEventListener> eventListeners;
protected ManagerConnectionState state = INITIAL;
private String eventMask;
/**
* Creates a new instance.
*/
public ManagerConnectionImpl()
{
this.id = idCounter.getAndIncrement();
this.responseListeners = new HashMap<String, SendActionCallback>();
this.responseEventListeners = new HashMap<String, ManagerEventListener>();
this.eventListeners = new ArrayList<ManagerEventListener>();
this.protocolIdentifier = new ProtocolIdentifierWrapper();
}
// the following two methods can be overriden when running test cases to
// return a mock object
protected ManagerReader createReader(Dispatcher dispatcher, Object source)
{
return new ManagerReaderImpl(dispatcher, source);
}
protected ManagerWriter createWriter()
{
return new ManagerWriterImpl();
}
/**
* Sets the hostname of the asterisk server to connect to.
* <p/>
* Default is <code>localhost</code>.
*
* @param hostname the hostname to connect to
*/
public void setHostname(String hostname)
{
this.hostname = hostname;
}
/**
没有合适的资源?快使用搜索试试~ 我知道了~
asterisk-java-1.0.0-m2-sources.zip_asterisk
共890个文件
java:447个
php:262个
class:39个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 89 浏览量
2022-09-23
16:13:03
上传
评论
收藏 1.8MB ZIP 举报
温馨提示
java程序实现asterisk的AGI接口,便于ASTERISK系统接口开发
资源推荐
资源详情
资源评论
收起资源包目录
asterisk-java-1.0.0-m2-sources.zip_asterisk (890个子文件)
movie.sql.bak 2KB
proguard.cfg 1KB
Grid.class 11KB
DBService.class 6KB
AllRecord.class 5KB
myCalendar$OnMyDateMenuItemClick.class 5KB
myCalendar.class 5KB
Record.class 4KB
Record$OnSettingMenuItemClick.class 4KB
Record$OnSaveMenuItemClick.class 3KB
AlarmAlert.class 3KB
Week.class 2KB
myCalendar$OnRecordRemindMenuItemClick.class 2KB
CalendarView.class 2KB
AllRecord$OnDeleteRecordMenuItemClick.class 2KB
CallAlarm.class 2KB
R$drawable.class 2KB
myCalendar$OnTodayMenuItemClick.class 1KB
Calendar.class 1KB
R$id.class 1KB
Border.class 1KB
About.class 1KB
CalendarParent.class 1KB
AllRecord$OnAddRecordMenuItemClick.class 1KB
myCalendar$OnAboutMenuItemClick.class 1KB
AlarmAlert$1.class 1KB
AllRecord$OnEditRecordMenuItemClick.class 1KB
R$color.class 949B
RemindSetting.class 798B
R.class 675B
R$dimen.class 646B
R$layout.class 632B
myCalendar$MenuItemClickParent.class 603B
AllRecord$MenuItemClickParent.class 597B
Record$MenuItemClickParent.class 579B
R$string.class 558B
Remind.class 419B
R$array.class 418B
R$raw.class 373B
R$attr.class 328B
CalendarElement.class 186B
.classpath 1KB
Thumbs.db 15KB
a2009091577014265.gif 8KB
.htaccess 13B
index.htm 1B
index.htm 1B
index.htm 1B
index.htm 0B
index.htm 0B
index.htm 0B
package.html 939B
package.html 819B
package.html 811B
package.html 796B
package.html 795B
package.html 791B
package.html 788B
package.html 775B
package.html 775B
package.html 772B
package.html 745B
package.html 739B
package.html 739B
package.html 730B
package.html 726B
package.html 725B
package.html 719B
admin.ini 46KB
adminhtml.ini 38KB
admin.ini 23KB
classes.ini 10KB
theme.ini 7KB
install.ini 7KB
default.ini 6KB
theme.ini 5KB
install.ini 4KB
default.ini 3KB
install.ini 1KB
translit.ini 707B
tablecolumns.ini 435B
ManagerConnectionImpl.java 48KB
AsteriskServerImpl.java 41KB
AgiChannel.java 30KB
ChannelManager.java 27KB
AsteriskChannelImpl.java 25KB
AsteriskChannel.java 21KB
AsteriskServer.java 20KB
ManagerConnection.java 17KB
AgiRequestImpl.java 16KB
AsteriskQueueImpl.java 16KB
Grid.java 16KB
ConfigFileReader.java 15KB
AgiChannelImpl.java 15KB
AbstractManagerEventListener.java 14KB
QueueManager.java 14KB
VoicemailUserEntryEvent.java 14KB
CdrEvent.java 14KB
OriginateAction.java 13KB
AgiOperations.java 12KB
共 890 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9
资源评论
Kinonoyomeo
- 粉丝: 74
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功