本文整理汇总了Java中org.sdnplatform.sync.thrift.SyncMessage类的典型用法代码示例。如果您正苦于以下问题:Java SyncMessage类的具体用法?Java SyncMessage怎么用?Java SyncMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SyncMessage类属于org.sdnplatform.sync.thrift包,在下文中一共展示了SyncMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: channelRead
import org.sdnplatform.sync.thrift.SyncMessage; //导入依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object message) throws Exception {
if (message instanceof SyncMessage) {
handleSyncMessage((SyncMessage)message, ctx.channel());
} else if (message instanceof List) {
for (Object i : (List<?>)message) {
if (i instanceof SyncMessage) {
try {
handleSyncMessage((SyncMessage)i,
ctx.channel());
} catch (Exception ex) {
ctx.fireExceptionCaught(ex);
}
}
}
} else {
handleUnknownMessage(ctx, message);
}
}
示例2: handleSyncMessage
import org.sdnplatform.sync.thrift.SyncMessage; //导入依赖的package包/类
/**
* Handle a generic {@link SyncMessage} and dispatch to an appropriate
* handler
* @param bsm the message
* @param channel the channel on which the message arrived
*/
protected void handleSyncMessage(SyncMessage bsm, Channel channel) {
switch (channelState) {
case OPEN:
case CONNECTED:
switch (bsm.getType()) {
case HELLO:
handshake(bsm.getHello(), channel);
break;
case ECHO_REQUEST:
handleEchoRequest(bsm.getEchoRequest(), channel);
break;
case ERROR:
handleError(bsm.getError(), channel);
break;
default:
// ignore
}
break;
case AUTHENTICATED:
handleSMAuthenticated(bsm, channel);
break;
}
}
示例3: getError
import org.sdnplatform.sync.thrift.SyncMessage; //导入依赖的package包/类
/**
* Generate an error message from the provided transaction ID and
* exception
* @param transactionId the transaction Id
* @param error the exception
* @param type the type of the message that generated the error
* @return the {@link SyncError} message
*/
protected SyncMessage getError(int transactionId, Exception error,
MessageType type) {
int ec = SyncException.ErrorType.GENERIC.getValue();
if (error instanceof SyncException) {
ec = ((SyncException)error).getErrorType().getValue();
} else {
logger.error("Unexpected error processing message " + transactionId
+ "(" + type + ")", error);
}
SyncError m = new SyncError();
m.setErrorCode(ec);
m.setMessage(error.getMessage());
ErrorMessage em = new ErrorMessage();
em.setError(m);
em.setType(type);
AsyncMessageHeader header = new AsyncMessageHeader();
header.setTransactionId(transactionId);
em.setHeader(header);
SyncMessage bsm = new SyncMessage(MessageType.ERROR);
bsm.setError(em);
return bsm;
}
示例4: handleHello
import org.sdnplatform.sync.thrift.SyncMessage; //导入依赖的package包/类
@Override
protected void handleHello(HelloMessage hello, Channel channel) {
remoteNodeId = hello.getNodeId();
org.sdnplatform.sync.thrift.Node n =
new org.sdnplatform.sync.thrift.Node();
n.setHostname(bootstrap.localNode.getHostname());
n.setPort(bootstrap.localNode.getPort());
if (bootstrap.localNode.getNodeId() >= 0)
n.setNodeId(bootstrap.localNode.getNodeId());
if (bootstrap.localNode.getDomainId() >= 0)
n.setDomainId(bootstrap.localNode.getDomainId());
ClusterJoinRequestMessage cjrm = new ClusterJoinRequestMessage();
AsyncMessageHeader header = new AsyncMessageHeader();
header.setTransactionId(bootstrap.transactionId.getAndIncrement());
cjrm.setHeader(header);
cjrm.setNode(n);
SyncMessage bsm =
new SyncMessage(MessageType.CLUSTER_JOIN_REQUEST);
bsm.setClusterJoinRequest(cjrm);
channel.writeAndFlush(bsm);
}
示例5: get
import org.sdnplatform.sync.thrift.SyncMessage; //导入依赖的package包/类
@Override
public List<Versioned<byte[]>> get(ByteArray key) throws SyncException {
StoreUtils.assertValidKey(key);
GetRequestMessage grm = new GetRequestMessage();
AsyncMessageHeader header = new AsyncMessageHeader();
header.setTransactionId(syncManager.getTransactionId());
grm.setHeader(header);
grm.setKey(key.get());
grm.setStoreName(storeName);
SyncMessage bsm = new SyncMessage(MessageType.GET_REQUEST);
bsm.setGetRequest(grm);
SyncReply reply = getReply(header.getTransactionId(), bsm);
return reply.getValues();
}
示例6: put
import org.sdnplatform.sync.thrift.SyncMessage; //导入依赖的package包/类
@Override
public void put(ByteArray key, Versioned<byte[]> value)
throws SyncException {
StoreUtils.assertValidKey(key);
PutRequestMessage prm = new PutRequestMessage();
AsyncMessageHeader header = new AsyncMessageHeader();
header.setTransactionId(syncManager.getTransactionId());
prm.setHeader(header);
prm.setVersionedValue(TProtocolUtil.getTVersionedValue(value));
prm.setKey(key.get());
prm.setStoreName(storeName);
SyncMessage bsm = new SyncMessage(MessageType.PUT_REQUEST);
bsm.setPutRequest(prm);
getReply(header.getTransactionId(), bsm);
}
示例7: RemoteIterator
import org.sdnplatform.sync.thrift.SyncMessage; //导入依赖的package包/类
public RemoteIterator() {
CursorRequestMessage crm = getCRM();
crm.setStoreName(storeName);
SyncMessage bsm = new SyncMessage(MessageType.CURSOR_REQUEST);
bsm.setCursorRequest(crm);
SyncReply reply;
try {
reply = getReply(crm.getHeader().getTransactionId(),
bsm);
} catch (SyncException e) {
throw new SyncRuntimeException(e);
}
this.cursorId = reply.getIntValue();
if (reply.getKeyedValues() != null)
currentChunk = reply.getKeyedValues().iterator();
}
示例8: getChunk
import org.sdnplatform.sync.thrift.SyncMessage; //导入依赖的package包/类
private Iterator<KeyedValues> getChunk() {
CursorRequestMessage crm = getCRM();
crm.setCursorId(cursorId);
SyncMessage bsm = new SyncMessage(MessageType.CURSOR_REQUEST);
bsm.setCursorRequest(crm);
SyncReply reply;
try {
reply = getReply(crm.getHeader().getTransactionId(),
bsm);
} catch (SyncException e) {
throw new SyncRuntimeException(e);
}
if (reply.getKeyedValues() == null ||
reply.getKeyedValues().size() == 0) return null;
return reply.getKeyedValues().iterator();
}
示例9: sendRequest
import org.sdnplatform.sync.thrift.SyncMessage; //导入依赖的package包/类
/**
* Send a request to the server and generate a future for the
* eventual reply. Note that this call can block if there is no active
* connection while a new connection is re-established or if the maximum
* number of requests is already pending
* @param xid the transaction ID for the request
* @param request the actual request to send
* @return A {@link Future} for the reply message
* @throws InterruptedException
*/
public Future<SyncReply> sendRequest(int xid,
SyncMessage request)
throws RemoteStoreException {
ensureConnected();
RemoteSyncFuture future = new RemoteSyncFuture(xid,
connectionGeneration);
futureMap.put(Integer.valueOf(xid), future);
if (futureMap.size() > MAX_PENDING_REQUESTS) {
synchronized (futureNotify) {
while (futureMap.size() > MAX_PENDING_REQUESTS) {
try {
futureNotify.wait();
} catch (InterruptedException e) {
throw new RemoteStoreException("Could not send request",
e);
}
}
}
}
channel.writeAndFlush(request);
return future;
}
示例10: messageReceived
import org.sdnplatform.sync.thrift.SyncMessage; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx,
MessageEvent e) throws Exception {
Object message = e.getMessage();
if (message instanceof SyncMessage) {
handleSyncMessage((SyncMessage)message, ctx.getChannel());
} else if (message instanceof List) {
for (Object i : (List<?>)message) {
if (i instanceof SyncMessage) {
try {
handleSyncMessage((SyncMessage)i,
ctx.getChannel());
} catch (Exception ex) {
Channels.fireExceptionCaught(ctx, ex);
}
}
}
} else {
handleUnknownMessage(ctx, message);
}
}
示例11: decode
import org.sdnplatform.sync.thrift.SyncMessage; //导入依赖的package包/类
@Override
protected Object decode(ChannelHandlerContext ctx,
Channel channel,
ChannelBuffer buffer) throws Exception {
List<SyncMessage> ms = null;
ChannelBuffer frame = null;
while (null != (frame = (ChannelBuffer) super.decode(ctx, channel,
buffer))) {
if (ms == null) ms = new ArrayList<SyncMessage>();
ChannelBufferInputStream is = new ChannelBufferInputStream(frame);
TCompactProtocol thriftProtocol =
new TCompactProtocol(new TIOStreamTransport(is));
SyncMessage bsm = new SyncMessage();
bsm.read(thriftProtocol);
ms.add(bsm);
}
return ms;
}
示例12: encode
import org.sdnplatform.sync.thrift.SyncMessage; //导入依赖的package包/类
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel,
Object message) throws Exception {
if (message instanceof SyncMessage) {
ChannelBuffer buf = new DynamicChannelBuffer(512);
ChannelBufferOutputStream os = new ChannelBufferOutputStream(buf);
TCompactProtocol thriftProtocol =
new TCompactProtocol(new TIOStreamTransport(os));
((SyncMessage) message).write(thriftProtocol);
ChannelBuffer len = ChannelBuffers.buffer(4);
len.writeInt(buf.readableBytes());
return ChannelBuffers.wrappedBuffer(len, buf);
}
return message;
}
示例13: handleHello
import org.sdnplatform.sync.thrift.SyncMessage; //导入依赖的package包/类
@Override
protected void handleHello(HelloMessage hello, Channel channel) {
remoteNodeId = hello.getNodeId();
org.sdnplatform.sync.thrift.Node n =
new org.sdnplatform.sync.thrift.Node();
n.setHostname(bootstrap.localNode.getHostname());
n.setPort(bootstrap.localNode.getPort());
if (bootstrap.localNode.getNodeId() >= 0)
n.setNodeId(bootstrap.localNode.getNodeId());
if (bootstrap.localNode.getDomainId() >= 0)
n.setDomainId(bootstrap.localNode.getDomainId());
ClusterJoinRequestMessage cjrm = new ClusterJoinRequestMessage();
AsyncMessageHeader header = new AsyncMessageHeader();
header.setTransactionId(bootstrap.transactionId.getAndIncrement());
cjrm.setHeader(header);
cjrm.setNode(n);
SyncMessage bsm =
new SyncMessage(MessageType.CLUSTER_JOIN_REQUEST);
bsm.setClusterJoinRequest(cjrm);
channel.write(bsm);
}
示例14: sendRequest
import org.sdnplatform.sync.thrift.SyncMessage; //导入依赖的package包/类
/**
* Send a request to the server and generate a future for the
* eventual reply. Note that this call can block if there is no active
* connection while a new connection is re-established or if the maximum
* number of requests is already pending
* @param xid the transaction ID for the request
* @param request the actual request to send
* @return A {@link Future} for the reply message
* @throws InterruptedException
*/
public Future<SyncReply> sendRequest(int xid,
SyncMessage request)
throws RemoteStoreException {
ensureConnected();
RemoteSyncFuture future = new RemoteSyncFuture(xid,
connectionGeneration);
futureMap.put(Integer.valueOf(xid), future);
if (futureMap.size() > MAX_PENDING_REQUESTS) {
synchronized (futureNotify) {
while (futureMap.size() > MAX_PENDING_REQUESTS) {
try {
futureNotify.wait();
} catch (InterruptedException e) {
throw new RemoteStoreException("Could not send request",
e);
}
}
}
}
channel.write(request);
return future;
}
示例15: handleHello
import org.sdnplatform.sync.thrift.SyncMessage; //导入依赖的package包/类
@Override
protected void handleHello(HelloMessage hello, Channel channel) {
remoteNodeId = hello.getNodeId();
org.sdnplatform.sync.thrift.Node n =
new org.sdnplatform.sync.thrift.Node();
n.setHostname(bootstrap.localNode.getHostname());
n.setPort(bootstrap.localNode.getPort());
if (bootstrap.localNode.getNodeId() >= 0)
n.setNodeId(bootstrap.localNode.getNodeId());
if (bootstrap.localNode.getDomainId() >= 0)
n.setDomainId(bootstrap.localNode.getDomainId());
ClusterJoinRequestMessage cjrm = new ClusterJoinRequestMessage();
AsyncMessageHeader header = new AsyncMessageHeader();
header.setTransactionId(bootstrap.transactionId.getAndIncrement());
cjrm.setHeader(header);
cjrm.setNode(n);
SyncMessage bsm =
new SyncMessage(MessageType.CLUSTER_JOIN_REQUEST);
bsm.setClusterJoinRequest(cjrm);
channel.writeAndFlush(bsm);
}