本文整理汇总了Java中org.quickserver.net.client.BlockingClient.sendBytes方法的典型用法代码示例。如果您正苦于以下问题:Java BlockingClient.sendBytes方法的具体用法?Java BlockingClient.sendBytes怎么用?Java BlockingClient.sendBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.quickserver.net.client.BlockingClient
的用法示例。
在下文中一共展示了BlockingClient.sendBytes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendCmdOutToAll
import org.quickserver.net.client.BlockingClient; //导入方法依赖的package包/类
private void sendCmdOutToAll(String data) throws TimeoutException {
PooledBlockingClient pbc[] = blockingClientPool.getOneBlockingClientForAllActiveHosts();
if (pbc == null) {
throw new TimeoutException("we do not have any client array [pbc] to connect to server!");
}
for (int i = 0; i < pbc.length; i++) {
try {
BlockingClient bc = pbc[i].getBlockingClient();
if (bc == null) {
throw new TimeoutException("we do not have any client[bc] to connect to server!");
}
bc.sendBytes(data, charset);
} catch (IOException e) {
if (pbc != null) {
logger.log(Level.WARNING, "We had an ioerror will close client! " + e, e);
pbc[i].close();
}
} finally {
blockingClientPool.returnBlockingClient(pbc[i]);
pbc[i] = null;
}
}
}
示例2: sendDataOut
import org.quickserver.net.client.BlockingClient; //导入方法依赖的package包/类
private String sendDataOut(String key, String data) throws TimeoutException {
ClientInfo ci = new ClientInfo();
ci.setClientKey(key);
PooledBlockingClient pbc = null;
try {
pbc = blockingClientPool.getBlockingClient(ci);
if (pbc == null) {
throw new TimeoutException("sdo: we do not have any client[pbc] to connect to server!");
}
BlockingClient bc = pbc.getBlockingClient();
if (bc == null) {
throw new TimeoutException("we do not have any client[bc] to connect to server!");
}
bc.sendBytes(data, charset);
return bc.readCRLFLine();
} catch (IOException e) {
if (pbc != null) {
logger.log(Level.WARNING, "We had an ioerror will close client! " + e, e);
pbc.close();
}
if(e instanceof TimeoutException) {
throw (TimeoutException) e;
} else {
throw new TimeoutException("We had ioerror " + e);
}
} finally {
if (pbc != null) {
blockingClientPool.returnBlockingClient(pbc);
}
}
}
示例3: readDataOutCAS
import org.quickserver.net.client.BlockingClient; //导入方法依赖的package包/类
private CASValue readDataOutCAS(String key, String data) throws TimeoutException {
long casUnique = 0;
ClientInfo ci = new ClientInfo();
ci.setClientKey(key);
PooledBlockingClient pbc = null;
try {
pbc = blockingClientPool.getBlockingClient(ci);
if (pbc == null) {
throw new TimeoutException("rdo: we do not have any client[pbc] to connect to server!");
}
BlockingClient bc = pbc.getBlockingClient();
if (bc == null) {
throw new TimeoutException("we do not have any client[bc] to connect to server!");
}
bc.sendBytes(data, charset);
String resMain = bc.readCRLFLine();
if (resMain == null) {
throw new TimeoutException("we got null reply!");
}
/*
VALUE <key> <flags> <bytes> [<cas unique>]\r\n
<data block>\r\n
END\r\n
*/
if (resMain.startsWith("VALUE ")) {
String cmdData[] = resMain.split(" ");
if (cmdData.length < 4) {
return null;
}
int flag = Integer.parseInt(cmdData[2]);
int bytes = Integer.parseInt(cmdData[3]);
if (cmdData.length >= 5) {
casUnique = Long.parseLong(cmdData[4]);
}
byte[] dataBuff = bc.readBytes(bytes);
//read the footer 7 char extra \r\nEND\r\n
bc.readBytes(7);
if (dataBuff == null) {
throw new TimeoutException("we don't have data!");
}
if (flag == FLAGS_GENRIC_STRING) {
return new CASValue(casUnique, new String(dataBuff, charset));
} else {
return new CASValue(casUnique, retriveObject(dataBuff));
}
} else if (resMain.equals("END")) {
return null;
} else {
logger.log(Level.WARNING, "unknown res got! : {0}", resMain);
throw new TimeoutException("unknown res got! : " + resMain);
}
} catch (IOException e) {
if (pbc != null) {
logger.log(Level.WARNING, "We had an ioerror will close client! " + e, e);
pbc.close();
}
if(e instanceof TimeoutException) {
throw (TimeoutException) e;
} else {
throw new TimeoutException("We had ioerror " + e);
}
} finally {
if (pbc != null) {
blockingClientPool.returnBlockingClient(pbc);
}
}
}
示例4: sendCmdOut
import org.quickserver.net.client.BlockingClient; //导入方法依赖的package包/类
private String sendCmdOut(String key, String data) throws TimeoutException {
ClientInfo ci = new ClientInfo();
ci.setClientKey(key);
PooledBlockingClient pbc = null;
try {
pbc = blockingClientPool.getBlockingClient(ci);
if (pbc == null) {
throw new TimeoutException("cmo: we do not have any client[pbc] to connect to server!");
}
BlockingClient bc = pbc.getBlockingClient();
if (bc == null) {
throw new TimeoutException("we do not have any client[bc] to connect to server!");
}
bc.sendBytes(data, charset);
String resMain = bc.readCRLFLine();
if (resMain == null) {
throw new TimeoutException("we got null reply!");
}
return resMain;
} catch (IOException e) {
if (pbc != null) {
logger.log(Level.WARNING, "We had an ioerror will close client! " + e, e);
pbc.close();
}
if(e instanceof TimeoutException) {
throw (TimeoutException) e;
} else {
throw new TimeoutException("We had ioerror " + e);
}
} finally {
if (pbc != null) {
blockingClientPool.returnBlockingClient(pbc);
}
}
}