Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!

Larry Cha Cha

Greenhorn
+ Follow
since Jun 06, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Larry Cha Cha

Sounds like a pretty good way to go Philippe, I think I may employ the same technique.
Do you think that it is good enough to just obtain the values for the combo boxes for location and name at the beginning? or should it dynamically change?
Since we don't have to have delete, and create in the GUI I don't think I will bother changing them as it will require passing back another array on every query to the db. By using the values in the JTable isn't the answer either as it doesn't truly reflect what's in the db.
The spec for the GUI says
"It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user."
Yet in the comments to the find method say:
"A non-null value in criteria[n] matches any field
value that begins with criteria[n]. (For example, "Fred" matches "Fred" or "Freddy".)"
To conform to the assignment, I would have to implement the find method above as required... and just not use it, using another one that does exactly the same thing but where the criteria exactly matches.
Clearly this is nonsense to do.
But which way to go I am not sure, either matching exactly or matching on the start of the string will contradict one of their requirements.
Cheers,
Larry
Ok it seems like all of my strings aren't null terminated at all but full of spaces, ie 32. A good old trim() seems to shorten it down so that problems gone now.
Does my technique of reading a full record into a ByteBuffer decoding it all to a CharBuffer and then sequentially obtaining each field like in the code above seem ok? It feels to me a bit long winded.
Thanks for your suggestions Phillipe and Jim.
I like some of those caching ideas and may consider using them as I've decided not to keep the record in memory (well this week anyway . )
In my read method I am reading one record at a time into a ByteBuffer and then decoding into a CharBuffer. Next I need to obtain each of the fields so I get a CharSequence of the first field being the hotel's name.
The toString method of the CharSequence leaves me with a string the length of HOTEL_NAME_BYTES so I then have to get up to the null character.
I asked in another thread for a quick e.g of how to do this which can be seen in the second snippet of code below, however it does not seem to work for me. The nullpos is returning -1 meaning that the null char couldn't be found.
If I print out each character in my 64 long string I get the hotel name followed by several blanks.
I feel like this is going to be a red faced moment for me but please help.
Cheers.

nd Bear I am not sure what you mean by the UBB CODE tag


When replying or creating a new topic there are buttons below the Instant UBB Code label, one of which is CODE. It simply adds an open and close tags which you should place your code in to format it correctly.
17 years ago
Thanks Stelian, I've been playing for eclipse for a few days now and am liking it a lot. I'll check out that plug in too.
Thanks for both of your thoughts, things are starting to make more sense now, but initially it all looked quite daunting.
What have other people done regarding storing the data in memory or just reading from file each time? I have two diff. views here and am still not certain which to go for.

However my instructions state that blank means the room is free - therefore under my instructions, 0 could be a valid owner number.


Mine says blank too, but doesn't this mean that each of the 8 bytes are 0? or is it the string 'blank'?
I haven't gotten around to looking into the field yet and it will be obvious when I do I guess.
Thanks Jim I was hopeing there was some util method that would do it but your snippet should do me fine.
Bear: It's from an existing file that stores their strings as null terminated, I wouldn't have done it myself that way.
17 years ago
I don't really know the ins and outs of how db's should work.
I have a few questions regarding the db.
1) My 1st question is what should the db be doing with all of the data from the file both when initially launched and when running.
My thoughts are to parse the file and create an ArrayList that holds all of the existing records in memory when it starts. If the user needs to search then the records are all there ready to go.
If a modification to the db needs to be done to I change the records in memory and then dump it all to a new file? or update the record in memory and the file at the same time.
2) Is storing the data as ByteBuffers in the ArrayList suitable? or would it be better to create Record objects with all of the fields as private member variables.
3) Does booking a room mean that the user selects a room as well as entering an id for the 'owner' field and that I just update this field with the owner number in it? (not allowing for 0) as this means the room is free
4) From the Data.java interface I must implement the delete comments say"// Deletes a record, making the record number and associated disk
// storage available for reuse." It sounds like I just remove this record from the file, however there is a valid data field flag that says 0x8000 implies deleted record so do I just change the records flag to this? or delete the record all together.
Thanks for all your help sorry if it's a bit long but I'm just starting out and seem to have so many questions. :/
How would I go about getting a string from a ByteBuffer or CharBuffer with the same contents, that is null terminated without checking every single character?
Cheers.
17 years ago
oh yeah... my worry is that poseidon will get rid of the community edition in the future and I'll have to copy everything over to argouml for eg.
I've been using text editors for ages but decided its time to make us of tools. I'm about to start doing the SCJD and think that netbeans for an ide and poseidon for designing uml may be the way to go.
I was wondering if people have had success with these and can suggest other free (windows 2k) tools.
For example is argouml good enough for the uml?
Cheers,
Laz
Hi. I have modified the SimpleQueueReceiver.java file provided only very slightly(to continue receiving, and to block until a new message arrives) and am having problems with dropped messages.
If I run their SimpleQueueSender with say 5 messages sent to the queue and subsequently run my Receiver (code below) messages all get through the first time that I add a new JmsDestination.
Once I ctrl-c my program, run their sender again, and then run my receiver the first message gets dropped. If I remove the queue and start it up again the problem works. Any ideas? I am a JMS noob so please be gentle
thanks.
-------------
import java.util.*;
import javax.jms.*;
import javax.naming.*;

/**
This class is responsible for continuously receiving JMS messages from
the queue that is passed in as an argument. A messageHandler method
is invoked on each subsequent message that is received.
*/
public class Receiver
{
// Flag used to indicate whether or not the program should continue to
// read messages.
private boolean m_continueReceiving = true;

// Contains the message listeners of this class.
private ArrayList m_messageListeners;

// The active connection for this Point to Point receiver.
private QueueConnection m_queueConnection = null;

// To receive messages from the queue.
private QueueReceiver m_queueReceiver = null;

/**
This method is responsible for setting the receiving flag
(m_continueReceiving to false) such that following the
retrieval of the next message, the program will stop receiving
and terminate.
*/
public void stopReceiving()
{
m_continueReceiving = false;
}

/**
Launch a new Receiver with the name of the queue.
*/
public static void main(String[] args)
{
// Check that a queue name was provided as an argument and exit displaying
// the correct usage if not.
if (args.length != 1)
{
System.out.println("Usage: java " +
"Receiver <queue-name>");

System.exit(1);
}

System.out.println("Queue name is " + args[0]);

// Initialise the receiver, and continuously receive messages
// notifying the listeners on arrival of each one.
Receiver receiver = new Receiver( args[0] );

// Start the Receiver to continuously receive messages.
receiver.startReceiving();
}

/**
The constructor of Receiver is responsible for initialising
the connection to the queue.
*/
public Receiver( String queueName )
{
Context jndiContext = null;
QueueConnectionFactory queueConnectionFactory = null;
QueueSession queueSession = null;
Queue queue = null;
m_messageListeners = new ArrayList();

// Create a JNDI API InitialContext object if none exists yet.
try
{
jndiContext = new InitialContext();
}
catch (NamingException e)
{
System.out.println("Could not create JNDI API " +
"context: " + e.toString());
System.exit(1);
}

// Look up connection factory and queue. If either does
// not exist, exit.
try
{
queueConnectionFactory = (QueueConnectionFactory)
jndiContext.lookup("QueueConnectionFactory");
queue = (Queue) jndiContext.lookup(queueName);
}
catch (NamingException e)
{
System.out.println("JNDI API lookup failed: " +
e.toString());
System.exit(1);
}

try
{
// Create a connection.
m_queueConnection = queueConnectionFactory.createQueueConnection();

// Create session from connection; false means session is
// not transacted.
queueSession = m_queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);

// Create receiver.
m_queueReceiver = queueSession.createReceiver(queue);

}
catch (JMSException e)
{
System.out.println("Exception occurred creating a connection, session, or receiver: " +
e.toString());
}
}

/**
This method is responsible for starting delivery of messages,
and the subsequent retrieval of messages in the queue, notifying
the MessageArrivalListeners after each one.
*/
public void startReceiving()
{
try
{
// Start the delivery of messages.
m_queueConnection.start();

// Receive all text messages from queue unless notified to stop.
while ( m_continueReceiving )
{
// Receive the next message that arrives. The argument of 0 indicates that the
// call will block indefinitely.
Message message = m_queueReceiver.receive(0);

if (message != null) {
if (message instanceof TextMessage) {
TextMessage messageText = (TextMessage) message;
System.out.println("Reading message: " +
messageText.getText());
} else {
System.out.println("In the else.");

}
}
}
}
catch( JMSException e )
{
System.out.println("Exception occurred when receiving a message: " +
e.toString());
}
}

}
------------------------