本文整理汇总了Java中org.telegram.mtproto.util.BytesCache类的典型用法代码示例。如果您正苦于以下问题:Java BytesCache类的具体用法?Java BytesCache怎么用?Java BytesCache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BytesCache类属于org.telegram.mtproto.util包,在下文中一共展示了BytesCache类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: run
import org.telegram.mtproto.util.BytesCache; //导入依赖的package包/类
@Override
public void run() {
setPriority(Thread.MIN_PRIORITY);
while (!MTProto.this.isClosed) {
if (Logger.LOG_THREADS) {
Logger.d(MTProto.this.TAG, "Response Iteration");
}
synchronized (MTProto.this.inQueue) {
if (MTProto.this.inQueue.isEmpty()) {
try {
MTProto.this.inQueue.wait();
} catch (InterruptedException e) {
return;
}
}
if (MTProto.this.inQueue.isEmpty()) {
continue;
}
}
MTMessage message = MTProto.this.inQueue.poll();
onMTMessage(message);
BytesCache.getInstance().put(message.getContent());
}
}
开发者ID:rubenlagus,项目名称:TelegramApi,代码行数:25,代码来源:MTProto.java
示例2: run
import org.telegram.mtproto.util.BytesCache; //导入依赖的package包/类
@Override
public void run() {
setPriority(Thread.MIN_PRIORITY);
while (!isClosed) {
if (Logger.LOG_THREADS) {
Logger.d(TAG, "Response Iteration");
}
synchronized (inQueue) {
if (inQueue.isEmpty()) {
try {
inQueue.wait();
} catch (InterruptedException e) {
return;
}
}
if (inQueue.isEmpty()) {
continue;
}
}
MTMessage message = inQueue.poll();
onMTMessage(message);
BytesCache.getInstance().put(message.getContent());
}
}
开发者ID:ardock,项目名称:telegram-mt,代码行数:25,代码来源:MTProto.java
示例3: readBytes
import org.telegram.mtproto.util.BytesCache; //导入依赖的package包/类
private byte[] readBytes(int count, int timeout, InputStream stream) throws IOException {
byte[] res = BytesCache.getInstance().allocate(count);
int offset = 0;
long start = System.nanoTime();
while (offset < count) {
int readed = stream.read(res, offset, count - offset);
Thread.yield();
if (readed > 0) {
offset += readed;
onRead();
} else if (readed < 0) {
throw new IOException();
} else {
if (System.nanoTime() - start > timeout * 1000000L) {
throw new IOException();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
Logger.e(TAG, e);
throw new IOException();
}
}
}
return res;
}
开发者ID:ardock,项目名称:telegram-mt,代码行数:27,代码来源:TcpContext.java
示例4: deserializeBody
import org.telegram.mtproto.util.BytesCache; //导入依赖的package包/类
@Override
public void deserializeBody(InputStream stream, TLContext context) throws IOException {
this.messageId = readLong(stream);
int contentSize = stream.available();
this.content = BytesCache.getInstance().allocate(contentSize);
readBytes(this.content, 0, contentSize, stream);
}
开发者ID:rubenlagus,项目名称:TelegramApi,代码行数:8,代码来源:MTRpcResult.java
示例5: deserializeBody
import org.telegram.mtproto.util.BytesCache; //导入依赖的package包/类
@Override
public void deserializeBody(InputStream stream, TLContext context) throws IOException {
this.messageId = readLong(stream);
this.seqNo = readInt(stream);
int size = readInt(stream);
this.content = BytesCache.getInstance().allocate(size);
readBytes(this.content, 0, size, stream);
}
开发者ID:rubenlagus,项目名称:TelegramApi,代码行数:9,代码来源:MTMessage.java
示例6: deserializeBody
import org.telegram.mtproto.util.BytesCache; //导入依赖的package包/类
@Override
public void deserializeBody(InputStream stream, TLContext context) throws IOException {
messageId = readLong(stream);
int contentSize = stream.available();
content = BytesCache.getInstance().allocate(contentSize);
readBytes(content, 0, contentSize, stream);
}
开发者ID:ardock,项目名称:telegram-mt,代码行数:8,代码来源:MTRpcResult.java
示例7: deserializeBody
import org.telegram.mtproto.util.BytesCache; //导入依赖的package包/类
@Override
public void deserializeBody(InputStream stream, TLContext context) throws IOException {
messageId = readLong(stream);
seqNo = readInt(stream);
int size = readInt(stream);
content = BytesCache.getInstance().allocate(size);
readBytes(content, 0, size, stream);
}
开发者ID:ardock,项目名称:telegram-mt,代码行数:9,代码来源:MTMessage.java
示例8: TelegramApi
import org.telegram.mtproto.util.BytesCache; //导入依赖的package包/类
/**
* Instantiates a new Telegram api.
*
* @param state the state
* @param _appInfo the _ app info
* @param _apiCallback the _ api callback
*/
public TelegramApi(AbsApiState state, AppInfo _appInfo, ApiCallback _apiCallback) {
this.INSTANCE_INDEX = instanceIndex.incrementAndGet();
this.TAG = "TelegramApi#" + this.INSTANCE_INDEX;
long start = System.currentTimeMillis();
this.apiCallback = _apiCallback;
this.appInfo = _appInfo;
this.state = state;
this.primaryDc = state.getPrimaryDc();
this.isClosed = false;
this.callback = new ProtoCallback();
Logger.d(this.TAG, "Phase 0 in " + (System.currentTimeMillis() - start) + " ms");
start = System.currentTimeMillis();
this.apiContext = new TLApiContext() {
private AtomicInteger integer = new AtomicInteger(0);
@Override
public TLObject deserializeMessage(int clazzId, InputStream stream) throws IOException {
if ((this.integer.incrementAndGet() % 10) == 9) {
Thread.yield();
}
return super.deserializeMessage(clazzId, stream);
}
@Override
public TLBytes allocateBytes(int size) {
return new TLBytes(BytesCache.getInstance().allocate(size), 0, size);
}
@Override
public void releaseBytes(TLBytes unused) {
BytesCache.getInstance().put(unused.getData());
}
};
Logger.d(this.TAG, "Phase 1 in " + (System.currentTimeMillis() - start) + " ms");
start = System.currentTimeMillis();
this.timeoutThread = new TimeoutThread();
this.timeoutThread.start();
this.dcThread = new ConnectionThread();
this.dcThread.start();
this.senderThread = new SenderThread();
this.senderThread.start();
Logger.d(this.TAG, "Phase 2 in " + (System.currentTimeMillis() - start) + " ms");
start = System.currentTimeMillis();
this.downloader = new Downloader(this);
this.uploader = new Uploader(this);
Logger.d(this.TAG, "Phase 3 in " + (System.currentTimeMillis() - start) + " ms");
}
开发者ID:rubenlagus,项目名称:TelegramApi,代码行数:62,代码来源:TelegramApi.java
注:本文中的org.telegram.mtproto.util.BytesCache类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论