view src/fdl/Tuple.java @ 7:1809e2b05824

Initial revision
author fuchita
date Sat, 16 Feb 2008 13:12:52 +0900
parents 083a0b5e12cc
children 609b288f47f9
line wrap: on
line source


package fdl;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.SocketChannel;


public class Tuple implements PSXQueueInterface {
    public int mode;
    public int id;
    public int seq;
    public int datalen;
    public ByteBuffer command;
    public ByteBuffer data;
    public Tuple next;    
    public SocketChannel ch;    
    
    static final boolean debug = false;

    public Tuple(SocketChannel _ch) {
    	ch = _ch;
    }

    public Tuple() {
    }

    public void setCommand(int _mode, int _seq) {
    	command = ByteBuffer.allocate(LINDA_HEADER_SIZE);
    	command.order(ByteOrder.BIG_ENDIAN);

    	command.putInt(LINDA_PACKET_LENGTH_OFFSET,
    				this.datalen+LINDA_HEADER_SIZE-INT_SIZE);
    	command.put(LINDA_MODE_OFFSET,(byte)_mode);
    	command.putShort(LINDA_ID_OFFSET,(short)this.id);
    	command.putInt(LINDA_SEQ_OFFSET,_seq);
    	command.putInt(LINDA_DATA_LENGTH_OFFSET,this.datalen);
    	command.rewind();
    }
    

    public void setCommand(int _mode, int _id, int _seq, int _datalen) {
    	command = ByteBuffer.allocate(LINDA_HEADER_SIZE);
    	command.order(ByteOrder.BIG_ENDIAN);

    	command.putInt(LINDA_PACKET_LENGTH_OFFSET,
    				_datalen+LINDA_HEADER_SIZE-INT_SIZE);
    	command.put(LINDA_MODE_OFFSET,(byte)_mode);
    	command.putShort(LINDA_ID_OFFSET,(short)_id);
    	command.putInt(LINDA_SEQ_OFFSET,_seq);
    	command.putInt(LINDA_DATA_LENGTH_OFFSET,_datalen);
    	command.rewind();
    }

    public void setTuple(int _mode,int _id, int _seq, int _datalen, ByteBuffer _data) {
	mode = _mode;
	id = _id;
	seq = _seq;
	datalen = _datalen;
	data = _data;
	
	if (debug) {
		System.out.print("setTuple mode:");
		System.out.println(mode);
		}
	//setCommand();
    }
    
    public void setSeq(int _seq) {
    	seq = _seq;
    }
    
    public void setMode(int _mode) {
    	mode = _mode;
    }

    public void setDataLength(int _datalength) {
    	datalen = _datalength;
    }
    
    public void setData(ByteBuffer _data) {
    	_data.rewind();
    	data = _data;
    }

    public int getMode() {
    	return mode;
    }

    /*public int getId() {
	return command.getShort(LINDA_ID_OFFSET);
    }*/

    public int getSeq() {
    	return seq;
    }

    public int getdataLength() {
    	return datalen;
    }
    public ByteBuffer getData() {
    	data.rewind();
    	return data;
    }
    
    public ByteBuffer getCommand() {
    	return this.command;
    }
    /*public ByteBuffer getCommand() {
    	command = ByteBuffer.allocate(LINDA_HEADER_SIZE);
    	command.order(ByteOrder.BIG_ENDIAN);
    	command.putInt(LINDA_PACKET_LENGTH_OFFSET, LINDA_HEADER_SIZE+datalen-INT_SIZE);
    	command.put(LINDA_MODE_OFFSET, (byte)mode);
    	command.putShort(LINDA_ID_OFFSET,(short)id);
    	command.putInt(LINDA_SEQ_OFFSET, seq);
    	command.putInt(LINDA_DATA_LENGTH_OFFSET, datalen);
    	command.rewind();
    	return command;
    }*/    
}