Mark Waes

Greenhorn
+ Follow
since Aug 06, 2008
Merit badge: grant badges
For More
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 Mark Waes

Thanks for the advice Bill.

When I wrote that I wasn't thinking of it from a performance perspective, but now you mention it, it is worth considering.

I may go the switch route eventually: this project is as much for the personal learning experience and fun as it is for producing something workable. I guess I have the luxury of not being bound to a customer's requirements/deadlines as well as balancing productivity with other factors.

When it comes down to it though, I will have to implement something to get it off the ground, so I will bear in mind your advice.

Many thanks.
13 years ago
Hi Ralph,

Yes it is a multi-player game and the events are typically centred around the players on it or the round/map just played. Obviously these things change frequently, so I would've thought it difficult to avoid instantiation in 99% of cases.

Back on topic... It seems static abstract methods aren't allowed, which makes sense I suppose, since abstract methods are supposed to be overridden. Many thanks for your suggestions though; you've definitely given me some new angles to explore.

13 years ago
Thanks for the replies all.

I did consider the enum/switch statement approach but I felt that wasn't much of an improvement over the elseifs since they're the same thing in principle. I'm of the opinion (thought I can't remember where from), that large elseif/switch should be avoided if possible. Since my posting this topic I stumbled across this interesting video on you tube: The Clean Code Talks -- Inheritance, Polymorphism, & Testing, where the speaker discusses structuring code in such a way as to minimise if statements. I think it is slightly related and interesting - I thought I would share.

I did also consider the map idea, but then I wasn't sure how to instantiate the required objects at run-time. I'll take a look at the Class.forName approach - I've not used this before, so it will be good to get my hands dirty on something new.

13 years ago
Hi,

I've written a small program which connects to a game server and listens for events published as things occur in the game. The server outputs a specific 'packet' format, which esentially can be thought of as an ArrayList containing Strings, with the first element being the event type, and the following elements being the event's parameters. There are 15 events currently (though more could be introduced) and each event can have a different number and type of parameters. Examples are:

  • OnJoin: The name of player who has just joined.
  • On Authenticated: The name of the player authenticated, and their GUID.


  • The above two are fairly simple, there are some events which returns lists of players with all their associated game stats (32 players x 9 different types of stat from memory).

    I was thinking of taking the packets mentioned previously and looking at the first element to see what kind of event had just occurred, then returning an object encapsulating that event, for example AuthenticatedPlayer would be a and object containing two strings for the name and GUID.

    However, to do this the first solution which comes to my mind is a longish list of if...elseif statement comparing Strings to establish what kind of event has occurred so the correct type of object can be instantiated. This didn't seem ideal to me as the if...elseif list would have to be maintained if new events were introduced and it doesn't seem a particularly elegant solution.

    Does anyone have any pointers as to alternative direction I could look at, or is the if...elseif (x14) a good approach?



    13 years ago
    I've investigated a little, and implemented a ScheduledExecutorService which initiates my Runnable every half a second or so and sends any packets before receiving any pending packets. This works fine, keeping a single thread busy some of the time, but my inexperience still leaves me with a question:

    Is it better to have more threads blocked waiting for I/O, or a less threads polling every ½ to 1 second and acting if anything needs doing? I'm unable to judge when the overhead or more threads would consume more resource than polling regularly.

    Some context: I would like this program to run on a virtualised Linux instance which also hosts a fairly low-traffic web site. If the game server is not populated, then I guess regular polling could be wasteful.

    ty

    mw
    Perhaps a ScheduledThreadPoolExecutor is the way forward...?
    Hi,

    I'm looking for some advice on structuring my program which I'm trying to write to communicate with a popular (ish) game's dedicated server so I can implement my own automated administration features. The specification requires sending and receiving of packets, which I have implemented as byte arrays using the a socket's input and outputsteam which is encapsulated in a class I've called ConnectionService.

    In practice, once the connection has been established and packets are flowing back and forth, there should be much more packets coming from the server then being sent to it, (though this is not guranteed). I therefore decided to use a thread each for the sockets input and output streams, with each picking up and placing into a BlockingQueue respectively. I had initially though about having a single thread writing to and reading from the streams, but I discarded this on the basis that a packet may not get sent while the thread was being blocked waiting for data from the inputstream.

    Here is my code so far (using Brian Goetz's exellent book, Java Concurrency in Practice, as help):



    There are some issues I need to tidy up with this, so please forgive any sins (such as not doing anything with caught exceptions).

    Here is the code I've used to test:



    This seams to work fine, but I'm thinking about how best to retrieve from the two BlockingQueues later on. Ideally I would like to implement a class called RequestResponsePair as each request should have a response which can be matched by the source of the packet and the packet's sequence number, so it made sense to have a single thread manage this. However this means that I'm back to the problem described earlier that my thread might be blocked while waiting for a packet to arrive when it should be sending one.

    One solution I did think of was not to block my 'pairing' thread (which could be the main thread), but this would mean repeatedly polling the inbound BlockingQueue and where ever the client initiated request come from (user input, or more likely as a result of analysing the inbound packets). In this scenario wouldn't this thread be in a busy-waiting loop, which I assumed was undesirable.

    Apols for the long-winded post.

    All help, and any other guidance/advice is greatly appreciated.

    Thanks

    Mark

    Hi,

    Each month we check a number of zip files saved to an Intranet to see if they've been updated, which (usually) happens quarterly, sometimes more often.

    To practice my coding skills I thought I'd write a small app which holds a list of URLs, and tests each of them to see if the file at the URL is 'newer' that the previous check performed. Currently I'm using a URLConnection object and was hoping to use its getLastModified() to determine if the file has been updated since the previous check.

    I've come to test my code on various files on the Internet and is seems not all files have a value returned from getLastModified().

    Is there a better way to query files in this way to see of they've been updated, or am I dependant on whether this information is present on a file by file basis?
    Assuming the code:

    Is calling:

    What do you notice about the signature of the method called in the if condition, and the signature of the method itself? (Summarised below)


    It's not incorrect in the sense it doesn't work, more that it is bad form.

    I assume:

    is a method which will return a boolean type, so when the method is evaluated it is like writing:


    which doesn't make sense if you think about it.

    So, you can simply drop the '== true' portion from your condition statement, and the same result will be achieved. To test for falsity you add the 'not' ('!') operator to the beginning:



    The result is code which is easier to read and therefore maintain.

    Hope that helps.
    The <applet> tag was deprecated in favour of the <object> tag which is supposed to do the same thing while being more flexible for future technologies and other objects other than applets.

    My understanding is that the <applet> tag tends to be implemented better on a wide range of browsers (particularly older ones), while the <object> tag is slowly being correctly implemented by the browser vendors.

    This might be useful:

    http://www.w3schools.com/TAGS/tag_object.asp wrote:
    The <object> tag is used to include objects such as images, audio, videos, Java applets, ActiveX, PDF, and Flash.

    The object element was intended to replace the img and applet elements. However, because of bugs and a lack of browser support this has not happened.

    The object support in browsers depend on the object type. Unfortunately, the major browsers use different codes to load the same object type.

    Luckily, the object element provides a solution. If the object element is not displayed, the code between the <object> and </object> tags will be executed. This way we can have several nested object elements (one for each browser).



    Thanks

    M
    14 years ago
    Hugh plays good roles in Blackadder. Who'd have guessed he can also does a convincing German accent!

    http://www.youtube.com/watch?v=LfrOo3qxVmM

    He plays a great character in House it's a nice change to see him play a serious miserable character instead of the comedic/light hearted roles I remember him for.
    14 years ago
    This looks ideal. I will explore in more detail when I get home.

    Thank you...
    14 years ago
    Hi all,

    Does anyone know of any J2EE applications or case studies I can download and open as a project in NetBeans to use as a learning tool?

    I find reviewing existing projects a good way to learn, and I would like to take things a step beyond the contrived course-work case studies I have studied so far.

    I am looking for something which incorporates a database layer, EJBs, Beans, Entity classes, JSPs and JSTL EL and other related J2EE topics. I'm not interested in 3rd party frame-works at this point such as Hibernate, I can progress on to those at a later date.

    I did try the JForum source, but I think it's a bit complex for the level I'm looking for, it doesn't use EJBs and there appears to be no suitable JSPs to review.

    Does anyone have any recommendations?

    Thanks

    M

    14 years ago
    Hi,

    This should be easy, but for the life of me I can't figure it out...

    I'm looking to provide user feeback when processing a large for-loop, and at each 10% milestone, print the message '10% Complete', '20% Complete' etc..

    my code is below, but it suffers from a problem when the countTarget instance variable is an odd number (prime numbers being a specific example) in that not all of the 10% milestones are printed.

    Regardless of the number of interations required by the for-loop, I would like to print feedback 10 times.



    Any help gratefully received...
    14 years ago