2009-02-05 05:20:37 +00:00
|
|
|
/*
|
2009-08-28 07:15:49 +00:00
|
|
|
* Copyright 2009 Red Hat, Inc.
|
2009-02-05 05:20:37 +00:00
|
|
|
*
|
2009-08-28 07:15:49 +00:00
|
|
|
* Red Hat licenses this file to you 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:
|
2009-02-05 05:20:37 +00:00
|
|
|
*
|
2009-08-28 07:15:49 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2009-02-05 05:20:37 +00:00
|
|
|
*
|
2009-08-28 07:15:49 +00:00
|
|
|
* 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.
|
2009-02-05 05:20:37 +00:00
|
|
|
*/
|
|
|
|
package org.jboss.netty.channel;
|
|
|
|
|
2009-02-05 05:56:47 +00:00
|
|
|
import static org.jboss.netty.channel.Channels.*;
|
|
|
|
|
2009-02-05 05:20:37 +00:00
|
|
|
/**
|
|
|
|
* The default {@link WriteCompletionEvent} implementation.
|
|
|
|
*
|
2010-01-26 09:04:19 +00:00
|
|
|
* @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
|
|
|
|
* @author <a href="http://gleamynode.net/">Trustin Lee</a>
|
2009-02-05 05:20:37 +00:00
|
|
|
*
|
|
|
|
* @version $Rev$, $Date$
|
|
|
|
*/
|
2009-02-11 09:47:53 +00:00
|
|
|
public class DefaultWriteCompletionEvent implements WriteCompletionEvent {
|
2009-02-05 05:20:37 +00:00
|
|
|
|
2009-02-05 05:56:47 +00:00
|
|
|
private final Channel channel;
|
2010-02-23 07:18:58 +00:00
|
|
|
private final long writtenAmount;
|
2009-02-05 05:20:37 +00:00
|
|
|
|
2010-02-23 07:18:58 +00:00
|
|
|
/**
|
|
|
|
* Creates a new instance.
|
|
|
|
*/
|
|
|
|
public DefaultWriteCompletionEvent(Channel channel, long writtenAmount) {
|
2009-02-05 05:56:47 +00:00
|
|
|
if (channel == null) {
|
|
|
|
throw new NullPointerException("channel");
|
|
|
|
}
|
2009-02-05 05:20:37 +00:00
|
|
|
if (writtenAmount <= 0) {
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
"writtenAmount must be a positive integer: " + writtenAmount);
|
|
|
|
}
|
|
|
|
|
2009-02-05 05:56:47 +00:00
|
|
|
this.channel = channel;
|
2009-02-05 05:20:37 +00:00
|
|
|
this.writtenAmount = writtenAmount;
|
|
|
|
}
|
|
|
|
|
2009-02-05 05:56:47 +00:00
|
|
|
public Channel getChannel() {
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ChannelFuture getFuture() {
|
|
|
|
return succeededFuture(getChannel());
|
|
|
|
}
|
|
|
|
|
2010-02-23 07:18:58 +00:00
|
|
|
public long getWrittenAmount() {
|
2009-02-05 05:20:37 +00:00
|
|
|
return writtenAmount;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
2009-02-08 16:12:18 +00:00
|
|
|
String channelString = getChannel().toString();
|
|
|
|
StringBuilder buf = new StringBuilder(channelString.length() + 32);
|
|
|
|
buf.append(channelString);
|
2009-02-16 11:59:33 +00:00
|
|
|
buf.append(" WRITTEN_AMOUNT: ");
|
2009-02-09 08:15:19 +00:00
|
|
|
buf.append(getWrittenAmount());
|
2009-02-05 05:20:37 +00:00
|
|
|
return buf.toString();
|
|
|
|
}
|
|
|
|
}
|