当前位置: 首页>>代码示例>>Java>>正文


Java Message.getLength方法代码示例

本文整理汇总了Java中org.jgroups.Message.getLength方法的典型用法代码示例。如果您正苦于以下问题:Java Message.getLength方法的具体用法?Java Message.getLength怎么用?Java Message.getLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jgroups.Message的用法示例。


在下文中一共展示了Message.getLength方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: down

import org.jgroups.Message; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public Object down(Event evt) {
    switch(evt.getType()) {
        case Event.MSG:
            Message msg=(Message)evt.getArg();
            if(msg.isFlagSet(Message.Flag.NO_FC))
                break;
            int length=msg.getLength();
            if(length == 0)
                break;
            return handleDownMessage(evt, msg, length);
        case Event.CONFIG:
            handleConfigEvent((Map<String,Object>)evt.getArg()); 
            break;
        case Event.VIEW_CHANGE:
            handleViewChange(((View)evt.getArg()).getMembers());
            break;
    }
    return down_prot.down(evt); // this could potentially use the lower protocol's thread which may block
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:21,代码来源:FC.java

示例2: down

import org.jgroups.Message; //导入方法依赖的package包/类
/**
 * Fragment a packet if larger than frag_size (add a header). Otherwise just pass down. Only
 * add a header if fragmentation is needed !
 */
public Object down(Event evt) {
    switch(evt.getType()) {

        case Event.MSG:
            Message msg=(Message)evt.getArg();
            long size=msg.getLength();
            if(size > frag_size) {
                fragment(msg);  // Fragment and pass down
                return null;
            }
            break;

        case Event.VIEW_CHANGE:
            handleViewChange((View)evt.getArg());
            break;

        case Event.SET_LOCAL_ADDRESS:
            local_addr=(Address)evt.getArg();
            break;
    }

    return down_prot.down(evt);  // Pass on to the layer below us
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:28,代码来源:FRAG2.java

示例3: up

import org.jgroups.Message; //导入方法依赖的package包/类
public Object up(Event evt) {
    switch(evt.getType()) {
        case Event.MSG:
            if(log.isTraceEnabled()) {
                Message msg=(Message)evt.getArg();
                long size=raw_buffer? msg.getLength() : msg.size();
                if(size >= min_size) {
                    StringBuilder sb=new StringBuilder(local_addr + ".up(): size of message buffer=");
                    sb.append(Util.printBytes(size)).append(", " + numHeaders(msg) + " headers");
                    if(print_msg)
                        sb.append(", headers=" + msg.printHeaders());
                    log.trace(sb);
                }
            }
            break;
    }
    return up_prot.up(evt);            // pass up to the layer above us
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:19,代码来源:SIZE.java

示例4: testBufferOffset

import org.jgroups.Message; //导入方法依赖的package包/类
public static void testBufferOffset() throws Exception {
    byte[] buf={'b', 'e', 'l', 'a', 'b', 'a', 'n'};
    Message m1=new Message(null, null, buf, 0, 4);
    Message m2=new Message(null, null, buf, 4, 3);

    byte[] b1, b2;

    b1=new byte[m1.getLength()];
    System.arraycopy(m1.getRawBuffer(), m1.getOffset(), b1, 0, m1.getLength());

    b2=new byte[m2.getLength()];
    System.arraycopy(m2.getRawBuffer(), m2.getOffset(), b2, 0, m2.getLength());

    Assert.assertEquals(4, b1.length);
    Assert.assertEquals(3, b2.length);
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:17,代码来源:MessageTest.java

示例5: down

import org.jgroups.Message; //导入方法依赖的package包/类
public Object down(Event evt) {
    if(evt.getType() == Event.MSG) {
        Message msg=(Message)evt.getArg();
        if(msg.getLength() > 0) {
            try {
                Long payload=(Long)msg.getObject();
                if(payload != null) {
                    if(payload == seqno) {
                        synchronized(this) {
                            if(num_discards < 3) {
                                num_discards++;
                                return null;
                            }
                        }
                    }
                    if(payload == duplicate) { // inject a duplicate message
                        super.down(evt); // pass it down, will passed down a second time by the default down_prot.down(evt)
                    }
                }
            }
            catch(Throwable t) {
                ;
            }
        }
    }
    return down_prot.down(evt);
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:28,代码来源:DISCARD_PAYLOAD.java

示例6: up

import org.jgroups.Message; //导入方法依赖的package包/类
public void up(MessageBatch batch) {
    int length=0;
    for(Message msg: batch) {
        if(msg.isFlagSet(Message.Flag.NO_FC))
            continue;

        Address dest=msg.getDest();
        boolean multicast=dest == null;
        boolean handle_multicasts=handleMulticastMessage();
        FcHeader hdr=(FcHeader)msg.getHeader(this.id);
        boolean process=(handle_multicasts && multicast) || (!handle_multicasts && !multicast) || hdr != null;
        if(!process)
            continue;

        if(hdr != null) {
            batch.remove(msg); // remove the message with a flow control header so it won't get passed up
            handleUpEvent(msg,hdr);
            continue;
        }
        length+=msg.getLength();
    }

    Address sender=batch.sender();
    long new_credits=0;
    if(length > 0)
        new_credits=adjustCredit(received, sender, length);

    if(!batch.isEmpty()) {
        try {
            up_prot.up(batch);
        }
        finally {
            if(new_credits > 0)
                sendCredit(sender, new_credits);
        }
    }
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:38,代码来源:FlowControl.java

示例7: up

import org.jgroups.Message; //导入方法依赖的package包/类
public void up(MessageBatch batch) {
    int length=0;
    for(Message msg: batch) {
        if(msg.isFlagSet(Message.Flag.NO_FC))
            continue;
        FcHeader hdr=(FcHeader)msg.getHeader(this.id);
        if(hdr != null) {
            batch.remove(msg); // don't pass message up as part of the batch
            handleUpEvent(hdr, msg);
            continue;
        }
        length+=msg.getLength();
    }

    Address sender=batch.sender();
    long new_credits=0;
    if(length > 0)
        new_credits=adjustCredit(received, sender, length);


    if(!batch.isEmpty()) {
        try {
            up_prot.up(batch);
        }
        finally {
            if(new_credits > 0)
                sendCredit(sender, new_credits);
        }
    }
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:31,代码来源:FC.java

示例8: sizeOfAllMessages

import org.jgroups.Message; //导入方法依赖的package包/类
/**
 * Computes the size of all messages currently in the table. This includes messages that haven't been purged or
 * compacted yet.
 * @param include_headers If true, {@link org.jgroups.Message#size()} is used, which will include the size of all
 * headers and the dest and src addresses. Else {@link org.jgroups.Message#getLength()} is used to compute.
 * Note that the latter is way more efficient.
 * @return Number of bytes of all messages.
 */
public long sizeOfAllMessages(boolean include_headers) {
    long retval=0;
    for(int i=0; i < matrix.length; i++) {
        Message[] row=matrix[i];
        if(row == null)
            continue;
        for(int j=0; j < row.length; j++) {
            Message msg=row[j];
            if(msg != null)
                retval+=include_headers? msg.size() : msg.getLength();
        }
    }
    return retval;
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:23,代码来源:RetransmitTable.java

示例9: length

import org.jgroups.Message; //导入方法依赖的package包/类
/** Returns the total number of bytes of the message batch (by calling {@link org.jgroups.Message#getLength()} on all messages) */
public int length() {
    int retval=0;
    Visitor<Integer> visitor=new Visitor<Integer>() {
        public Integer visit(Message msg, MessageBatch batch) {
            return msg != null? msg.getLength() : 0;
        }
    };
    for(int i=0; i < index; i++)
        retval+=visitor.visit(messages[i], this);
    return retval;
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:13,代码来源:MessageBatch.java

示例10: down

import org.jgroups.Message; //导入方法依赖的package包/类
public Object down(Event evt) {
    if(evt.getType() == Event.MSG) {
        Message msg=(Message)evt.getArg();
        int length=msg.getLength();
        num_msgs_in_period.incrementAndGet();
        bytes_in_period.addAndGet(length);
    }
    return null;
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:10,代码来源:RATE_LIMITER_Test.java

示例11: messageReceived

import org.jgroups.Message; //导入方法依赖的package包/类
/**
 * Checks if any of the messages in the list has a non-zero length
 * @param list
 * @return
 */
public boolean messageReceived(BoundedList<Message> list) {
    if(list == null || list.isEmpty())
        return false;
    for(Message msg: list)
        if(msg.getLength() > 0)
            return true;
    return false;
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:14,代码来源:BecomeServerTestHelper.java

示例12: down

import org.jgroups.Message; //导入方法依赖的package包/类
/**
 * We compress the payload if it is larger than <code>min_size</code>. In this case we add a header containing
 * the original size before compression. Otherwise we add no header.<br/>
 * Note that we compress either the entire buffer (if offset/length are not used), or a subset (if offset/length
 * are used)
 * @param evt
 */
public Object down(Event evt) {
    if(evt.getType() == Event.MSG) {
        Message msg=(Message)evt.getArg();
        int length=msg.getLength(); // takes offset/length (if set) into account
        if(length >= min_size) {
            byte[] payload=msg.getRawBuffer(); // here we get the ref so we can avoid copying
            byte[] compressed_payload=new byte[length];
            Deflater deflater=null;
            try {
                deflater=deflater_pool.take();
                deflater.reset();
                deflater.setInput(payload, msg.getOffset(), length);
                deflater.finish();
                deflater.deflate(compressed_payload);
                int compressed_size=deflater.getTotalOut();

                if(compressed_size < length ) { // JGRP-1000
                    byte[] new_payload=new byte[compressed_size];
                    System.arraycopy(compressed_payload,0,new_payload,0,compressed_size);
                    Message copy=msg.copy(false).setBuffer(new_payload).putHeader(this.id,new CompressHeader(length));
                    if(log.isTraceEnabled())
                        log.trace("down(): compressed payload from " + length + " bytes to " + compressed_size + " bytes");
                    return down_prot.down(new Event(Event.MSG, copy));
                }
                else {
                    if(log.isTraceEnabled())
                        log.trace("down(): skipping compression since the compressed message (" + compressed_size +
                                    ") is not smaller than the original (" + length + ")");
                }
            }
            catch(InterruptedException e) {
                Thread.currentThread().interrupt(); // set interrupt flag again
                throw new RuntimeException(e);
            }
            finally {
                if(deflater != null)
                    deflater_pool.offer(deflater);
            }
        }
    }
    return down_prot.down(evt);
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:50,代码来源:COMPRESS.java

示例13: down

import org.jgroups.Message; //导入方法依赖的package包/类
public Object down(Event evt) {
    if(evt.getType() == Event.MSG) {
        Message msg=(Message)evt.getArg();
        int len=msg.getLength();
        if(len == 0 || msg.isFlagSet(Message.Flag.NO_FC))
            return down_prot.down(evt);

        lock.lock();
        try {
            if(len > max_bytes) {
                log.error("message length (" + len + " bytes) exceeded max_bytes (" + max_bytes + "); " +
                        "adjusting max_bytes to " + len);
                max_bytes=len;
            }

            if(num_bytes_sent_in_period + len > max_bytes) { // size exceeded
                long current_time=System.nanoTime();
                long block_time=time_period_ns - (current_time - current_period_start);
                if(block_time > 0) {
                    LockSupport.parkNanos(block_time);
                    num_blockings++;
                    total_block_time+=block_time;
                }
                current_period_start=block_time > 0? current_time + block_time : System.nanoTime();
                num_bytes_sent_in_period=0;
            }
        }
        finally {
            num_bytes_sent_in_period+=len;
            lock.unlock();
        }

        return down_prot.down(evt);
    }

    if(evt.getType() == Event.CONFIG) {
        Map<String,Object> map=(Map<String, Object>)evt.getArg();
        Integer tmp=map != null? (Integer)map.get("frag_size") : null;
        if(tmp != null)
            frag_size=tmp;
        if(frag_size > 0) {
            if(max_bytes % frag_size != 0) {
                if(log.isWarnEnabled())
                    log.warn("For optimal performance, max_bytes (" + max_bytes +
                               ") should be a multiple of frag_size (" + frag_size + ")");
            }
        }
    }

    return down_prot.down(evt);
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:52,代码来源:RATE_LIMITER.java

示例14: updateStats

import org.jgroups.Message; //导入方法依赖的package包/类
private void updateStats(Message msg, short direction) {
    int     length;
    HashMap map;
    boolean mcast;
    Address dest, src;

    if(msg == null) return;
    length=msg.getLength();
    dest=msg.getDest();
    src=msg.getSrc();
    mcast=dest == null;

    if(direction == UP) { // received
        received_msgs++;
        received_bytes+=length;
        if(mcast) {
            received_mcasts++;
            received_mcast_bytes+=length;
        }
        else {
            received_ucasts++;
            received_ucast_bytes+=length;
        }
    }
    else {                // sent
        sent_msgs++;
        sent_bytes+=length;
        if(mcast) {
            sent_mcasts++;
            sent_mcast_bytes+=length;
        }
        else {
            sent_ucasts++;
            sent_ucast_bytes+=length;
        }
    }

    Address key=direction == UP? src : dest;
    map=direction == UP? received : sent;
    Entry entry=(Entry)map.get(key);
    if(entry == null) {
        entry=new Entry();
        map.put(key, entry);
    }
    entry.msgs++;
    entry.bytes+=length;
    if(mcast) {
        entry.mcasts++;
        entry.mcast_bytes+=length;
    }
    else {
        entry.ucasts++;
        entry.ucast_bytes+=length;
    }
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:56,代码来源:STATS.java


注:本文中的org.jgroups.Message.getLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。