This week's book giveaway is in the Go forum.
We're giving away four copies of Head First Go and have Jay McGavren on-line!
See this thread for details.
Win a copy of Head First Go this week in the Go forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Convention for designing a class that utilizes a serialized object on first run.  RSS feed

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings! This is my first forum post.

I'm designing a headless application (for one machine) that performs daily web harvesting and stores the data in a serialized class, which is a very basic CRM. The application compares data against data that is in the serialized CRM class. But on the first run of this application there will be no .ser file. My question is: What is, if any, the conventional way to design this application in regards to handling the first run? Currently, I'm manually toggling a boolean flag, and, uh ... I know that's poor form (but it's easy). How would an experienced developer go about structuring this? I don't need code, just some guidance would be perfect.

Thanks,
David
 
Ranch Hand
Posts: 90
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello David,

Welcome to the ranch!

From your post I gather that at the moment your application is running ok.

Regarding the first run solution I'd just point out the idea of "Occam's Razor",
which states that "simpler solutions are more likely to be correct than complex
ones".

So, I think, if your application is in the early design iterations, then if it works
it works, regardless if it looks "too simple"
 
Marshal
Posts: 24199
54
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

David Gillette wrote:The application compares data against data that is in the serialized CRM class. But on the first run of this application there will be no .ser file.



As an experienced developer, I'd have some questions about that brief requirement description. The main question is: You don't say what should happen when there is no data to compare.

My first guess at the approach is like this:

1. Get the new data.

2. Get the old data from the .ser file.

3. If you got some data, then do the comparison.

4. Write the new data to the .ser file.

But as you see, I have made an assumption about what "compare data against data" means when there's no old version to compare. Maybe it's more complicated than that.
 
David Gillette
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the speedy replies.

Ok, so, the requirement description needs improvement. The following should describe the flow in greater detail:

1) Get the new data
2) Check if this run is the first run of the application (and do either 3 or 4)
3) If this is the first run, skip comparison against old data and serialize new data
4) If this is not the first run, check if .ser exists (and do either 5 or 6)
5) If .ser exists, perform comparison against old data, do the hokey pokey, merge qualified new data with old data, and serialize data to .ser (and email a backup or something)
6) If .ser does not exist, stop, and maybe send an email requesting file restoration

The application needs to know if this is or is not the first run independent of whether the .ser exists, because after running for six months, there will a substantial amount of data and the application should not run until the file is restored.

I hope this describes what is happening in greater detail. Please let me know if I can provide further clarification.

 
Paul Clapham
Marshal
Posts: 24199
54
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

David Gillette wrote:2) Check if this run is the first run of the application (and do either 3 or 4)



That raises another question. I had assumed that the absence of a .ser file would mean this was the first run. But apparently it's possible to run the application one or more times and then be in a situation where there is no .ser file? If so, what information tells you that it's the first run?
 
David Gillette
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm attempting to handle a situation in which the .ser is missing, corrupt or the computer was accidentally dropped in a metal shredder. Well, maybe not the metal shredder part, that would require something all together different. Let's just say in the case where the file became missing or corrupt. The application (this specific .jar sitting on a single machine) should have something that says, "this isn't my first run" and "there's no .ser file", "Danger!, Danger!" So...

Your Socratic method has taken us to the real question:

What should be used to tell if this is the application's first run?
 
David Gillette
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or, more so, what should be used so that the application:
1) Knows if there should be an .ser file?
2) Makes one .ser file that is "strictly" associated with this specific instance of the application?

I'm fairly certain that's what I'm attempting!
 
Paul Clapham
Marshal
Posts: 24199
54
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's possible that the .ser file became corrupt because maybe of some programming error or environmental glitch, but you can deal with that when you try to read it in and find that it has become corrupt. The case where some evildoer or careless administrator deletes the .ser file: if you want to deal with that then yes, you need some other way of knowing that this isn't the first run and that therefore there should be a .ser file in place.

You could try to handle that situation by having the application write some information somewhere, which it can then look for to know whether this is the first run. But then you have the same problem: somebody or something can erase that information.
 
David Gillette
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to write to something inside the .jar, like an .ini file?
 
Marshal
Posts: 63496
207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, a .jar file s simply a posh version of a .zip fle, so you probably can include an .ini file. Never tried it myself.
 
David Gillette
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you think would be the best or a conventional approach ... if an application needs to know if this is the first run and needs to track that information inside the .jar?
 
Ranch Hand
Posts: 277
2
Fedora Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could add logging and have the app read the log.  Surely nobody is going to mess with the logs.
 
David Gillette
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all very much for helping me think this through.

I believe I've found, an ugly, but simple approach:

1) drop firstRun.txt in the .jar
2) check for presence of firstRun.txt ( do 3 or 4 )
3) if firstRun.txt exists, this is first run -> run application -> when finished send timeout cmd command to delete firstRun.txt -> exit application before timeout ends
4) if firstRun.txt does not exist, this is not first run -> check for .ser and do stuff

Any thoughts? Is this the worst thing you've ever seen?

There must be a more sophisticated way of doing this...
 
Paul Clapham
Marshal
Posts: 24199
54
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't update a JAR file. If you really need to modify the contents of a JAR file, what you have to do is to extract the resources that you need from the JAR, and then build a new JAR from those. And then delete the old JAR and replace it by the new one.

This doesn't sound like a practical thing to do, especially since you'll be using the JAR file during that process.

I don't believe that you explained why it was important to know whether a run of the application was the first run. Perhaps it might turn out that it's not that important after all?
 
David Gillette
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The application needs to know if this is the first run because after, say, six months the .ser will contain important information against which the new data will be qualified. The .ser is a basic CRM database and will contain some metrics and flags for contacts. Continuity of data needs to be maintained for each run to cultivate a professional relationship with contacts. For example, the CRM has an exclusion flag and time stamp information on each object to track things like a hard bounces, requests for no contact, last contact date, and so forth. This is why after a first run, there should be a trigger that alerts the application to stop in the event the .ser file is missing or corrupt.
 
David Gillette
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe the following would be a better solution:

1) the application upon startup logs into an email account
2) check for a designated folder (do either 3 or 4)
3) if folder does not exist, this is first run -> run application under first run condition -> create designated folder
4) if folder exists, this is not first run -> check for .ser and do stuff

This approach might be more practical because the email account will be used to store backups and programmatically replace the .ser should it become missing or corrupt.
 
Paul Clapham
Marshal
Posts: 24199
54
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, that's another solution which can be broken by malice or incompetence. Realistically I think that every such solution involves the application creating some external resource when it's first run; it's up to you to decide how much you want to do to prevent that external resource from being deleted.

Another thing to consider is that the application must be able to find that external resource reliably. For your most recent solution, consider that it's possible for the e-mail server to be inaccessible for several reasons. That would (hopefully) cause the application to fail to start because it couldn't log into the e-mail account.
 
David Gillette
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without getting too philosophical, it is highly improbable there is a way to prevent any being with the time, resources, and aptitude from causing any malice. As far as incompetence goes ... well, I have a predilection the confidently incompetent will destroy everything by virtue of unintended consequences. My intention is merely to create a single-step safety mechanism, just in case. (The CIA rejected my application as a developer on grounds of "National Security" by the way.)

Given the application requires WAN access for all of its various functions, yes, the application should check for WAN/Email/website issues and handle those situations appropriately. Good stuff...

Thank you! All of you have been very helpful in refining my thoughts and guiding me, like Socratic Psychopomps, toward a practical approach.
 
It would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!