use of org.jboss.netty.channel.Channel in project hadoop by apache.
the class OpenFileCtx method doSingleWrite.
private void doSingleWrite(final WriteCtx writeCtx) {
Channel channel = writeCtx.getChannel();
int xid = writeCtx.getXid();
long offset = writeCtx.getOffset();
int count = writeCtx.getCount();
WriteStableHow stableHow = writeCtx.getStableHow();
FileHandle handle = writeCtx.getHandle();
if (LOG.isDebugEnabled()) {
LOG.debug("do write, fileId: " + handle.getFileId() + " offset: " + offset + " length: " + count + " stableHow: " + stableHow.name());
}
try {
// The write is not protected by lock. asyncState is used to make sure
// there is one thread doing write back at any time
writeCtx.writeData(fos);
RpcProgramNfs3.metrics.incrBytesWritten(writeCtx.getCount());
long flushedOffset = getFlushedOffset();
if (flushedOffset != (offset + count)) {
throw new IOException("output stream is out of sync, pos=" + flushedOffset + " and nextOffset should be" + (offset + count));
}
// Reduce memory occupation size if request was allowed dumped
if (writeCtx.getDataState() == WriteCtx.DataState.ALLOW_DUMP) {
synchronized (writeCtx) {
if (writeCtx.getDataState() == WriteCtx.DataState.ALLOW_DUMP) {
writeCtx.setDataState(WriteCtx.DataState.NO_DUMP);
updateNonSequentialWriteInMemory(-count);
if (LOG.isDebugEnabled()) {
LOG.debug("After writing " + handle.getFileId() + " at offset " + offset + ", updated the memory count, new value: " + nonSequentialWriteInMemory.get());
}
}
}
}
if (!writeCtx.getReplied()) {
if (stableHow != WriteStableHow.UNSTABLE) {
LOG.info("Do sync for stable write: " + writeCtx);
try {
if (stableHow == WriteStableHow.DATA_SYNC) {
fos.hsync();
} else {
Preconditions.checkState(stableHow == WriteStableHow.FILE_SYNC, "Unknown WriteStableHow: " + stableHow);
// Sync file data and length
fos.hsync(EnumSet.of(SyncFlag.UPDATE_LENGTH));
}
} catch (IOException e) {
LOG.error("hsync failed with writeCtx: " + writeCtx, e);
throw e;
}
}
WccAttr preOpAttr = latestAttr.getWccAttr();
WccData fileWcc = new WccData(preOpAttr, latestAttr);
if (writeCtx.getOriginalCount() != WriteCtx.INVALID_ORIGINAL_COUNT) {
LOG.warn("Return original count: " + writeCtx.getOriginalCount() + " instead of real data count: " + count);
count = writeCtx.getOriginalCount();
}
WRITE3Response response = new WRITE3Response(Nfs3Status.NFS3_OK, fileWcc, count, stableHow, Nfs3Constant.WRITE_COMMIT_VERF);
RpcProgramNfs3.metrics.addWrite(Nfs3Utils.getElapsedTime(writeCtx.startTime));
Nfs3Utils.writeChannel(channel, response.serialize(new XDR(), xid, new VerifierNone()), xid);
}
// Handle the waiting commits without holding any lock
processCommits(writeCtx.getOffset() + writeCtx.getCount());
} catch (IOException e) {
LOG.error("Error writing to fileId " + handle.getFileId() + " at offset " + offset + " and length " + count, e);
if (!writeCtx.getReplied()) {
WRITE3Response response = new WRITE3Response(Nfs3Status.NFS3ERR_IO);
Nfs3Utils.writeChannel(channel, response.serialize(new XDR(), xid, new VerifierNone()), xid);
// Keep stream open. Either client retries or SteamMonitor closes it.
}
LOG.info("Clean up open file context for fileId: " + latestAttr.getFileId());
cleanup();
}
}
use of org.jboss.netty.channel.Channel in project storm by nathanmarz.
the class StormClientHandler method channelConnected.
@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent event) {
//register the newly established channel
Channel channel = event.getChannel();
client.setChannel(channel);
LOG.debug("connection established to a remote host");
//send next request
try {
sendRequests(channel, client.takeMessages());
} catch (InterruptedException e) {
channel.close();
}
}
use of org.jboss.netty.channel.Channel in project pinpoint by naver.
the class DefaultPinpointClientFactory method reconnect.
public ChannelFuture reconnect(final SocketAddress remoteAddress) {
if (remoteAddress == null) {
throw new NullPointerException("remoteAddress");
}
ChannelPipeline pipeline;
final ClientBootstrap bootstrap = this.bootstrap;
try {
pipeline = bootstrap.getPipelineFactory().getPipeline();
} catch (Exception e) {
throw new ChannelPipelineException("Failed to initialize a pipeline.", e);
}
PinpointClientHandler pinpointClientHandler = (DefaultPinpointClientHandler) pipeline.getLast();
pinpointClientHandler.initReconnect();
// Set the options.
Channel ch = bootstrap.getFactory().newChannel(pipeline);
boolean success = false;
try {
ch.getConfig().setOptions(bootstrap.getOptions());
success = true;
} finally {
if (!success) {
ch.close();
}
}
// Connect.
return ch.connect(remoteAddress);
}
use of org.jboss.netty.channel.Channel in project pinpoint by naver.
the class PinpointClientStateTest method getSocketHandler.
PinpointClientHandler getSocketHandler(ChannelFuture channelConnectFuture, SocketAddress address) {
if (address == null) {
throw new NullPointerException("address");
}
Channel channel = channelConnectFuture.getChannel();
PinpointClientHandler pinpointClientHandler = (PinpointClientHandler) channel.getPipeline().getLast();
pinpointClientHandler.setConnectSocketAddress(address);
return pinpointClientHandler;
}
use of org.jboss.netty.channel.Channel in project neo4j by neo4j.
the class NetworkReceiver method listen.
private int listen(int minPort, int maxPort) throws URISyntaxException, ChannelException {
ChannelException ex = null;
for (int checkPort = minPort; checkPort <= maxPort; checkPort++) {
try {
String address = config.clusterServer().getHost();
InetSocketAddress localAddress;
if (address == null || address.equals(INADDR_ANY)) {
localAddress = new InetSocketAddress(checkPort);
} else {
localAddress = new InetSocketAddress(address, checkPort);
bindingDetected = true;
}
Channel listenChannel = serverBootstrap.bind(localAddress);
listeningAt(getURI(localAddress));
channels.add(listenChannel);
return checkPort;
} catch (ChannelException e) {
ex = e;
}
}
nioChannelFactory.releaseExternalResources();
throw ex;
}
Aggregations