server side processing question

server side processing question

Old forum URL: forums.lhotka.net/forums/t/3599.aspx


Ton Smeets posted on Wednesday, September 26, 2007

Hello,

I searched the forum for about 2 hours, and didn't find any answer. My application should be prepared for getting to be used in a network with an application server and maybe in the future a database server.

To do this, I need to know how I can create a document number that is unique. Not a Guid. It going to be something like doc001, doc002, doc003 and so on. This number is will be created with a business object, and should be accessed by all clients to retrieve that document number with a static method. The business object then increases the number by 1.When the application shuts down, the object writes the last used document number to the database. When the application starts up, the object fetches the number from the database.

This sounds like a simple business object, but I cann't figure out where I must place it in my code. The business object has to run on the application server, but should also work on a stand alone computer.

Can I call the factory method from such an object within the DataPortal_Create() factory-method? And can I still do this when the dataportal runs local?

Thanks.

 

Curelom replied on Wednesday, September 26, 2007

There are a couple of options for doing this.  I believe the most common is to have the create method assign a negative number for the document and when the dataportal insert is called, it would then assign a permanent number to the document.  Another option would work if your application can always connect to the server, would be to create a web service that would give out unique ids.

Ton Smeets replied on Wednesday, September 26, 2007

I'm not talking about a primary key or id. Just a property that gets its value from another object using a factory method. That object holds the last given number and creates a new number by incrementing the last used number with 1.

The purpose here is to serve multiple clients with a sequence of unique numbers. Something like global static properties. And it should run on either the application server or on a stand alone computer.

Curelom replied on Wednesday, September 26, 2007

Maybe I'm not understanding what you are trying to do completely. The methods I stated would work for any property.  It would be difficult to implement something like this without interaction with a server.  You would hit the server each time you need a document number via dp_execute, web service, db call.  If you want to wrap that in a factory, that would work too.  If you are working away form a server, you would have to come up with a different naming convention for each client, or have each client reserve some numbers.

Ton Smeets replied on Wednesday, September 26, 2007

Well, I'm gone try to explain what I am looking for. Imagin a dozen clients working with an application server. All these clients can create a shipping document. That document is not an object, just a printed document. That document should have a number on it. The only way I can think off having a sequential range of numbers created when all these clients print documents, is to have an object on the application server that calculates a new document number every time a client asks for that number. Beside this, the user of my programm should be able to change that document number when he/she starts using my programm. Maybe the user wants to start with a document number 4123, for what reason he may have.

I'm trying to figure out how i can use an object on the application server that stays alive as long as the server runs. It shoult use static values, or factory methods to pass values back to the client. I just don't now how to create that object on te server and how to keep it running. I never programmed a server side before.

ReadOnlyChild replied on Wednesday, September 26, 2007

Think about it like.... all code you put in the DataPortal_XYZ methods will be ran on the serverside, this thought extends to methods called by these DataPortal_XYZ methods, like the ExecuteFetch(), FetchChildren(), etc... (as long as these same methods are not called by other methods that are NOT DataPortal_XYZ!!)

so just code the class that serves the number like follows: (stick to only using this on the DP_XYZ methods)

_docNumberProperty = NumberGenerator.GetNextNumber();
// this class does not even need to inherit from BusinessBase because it will never use the dataportal, it is already always in the server.

that should cover both Local and n-tier configurations

... about letting the end user specify the beginning number, then my proposal needs some kind of override to not use the .GetNextNumber() static method.

Curelom replied on Wednesday, September 26, 2007

Ah, that makes more sense.  

If you are using remoting with csla, any code being run in the dataportal is run on the server.

If you aren't using remoting, probably the simplest way would be to create a web service on the server (This option is only available if you have a web server on your server).  Web service projects are simple to create and there are plenty of examples out there.  This takes care of the server staying alive, etc.  On the web service you would have a method such as GetNextDocNumber.

Your client objects would then connect to the web service and call that method which would return the next number.  This takes just a few lines of code.

Now for the nuts and bolts of the GetNextDocNumber.

You need a place to store the current number, in case the server goes down, when it starts up again, you don't want it to start at 1 again.  You could put the number in an xml document, or in a database.

When the user calls GetNextDocNumber, you would grab the number from whatever location you are storing it, save the incremented number, then return the number to the user.  If you are putting the number in an xml doc, you will need to be careful with threading issues, such as 2 clients getting a number at the same time.

There are a number of things you could do to optimize this, but this should get you started. 

Ton Smeets replied on Thursday, September 27, 2007

The application server should run in a LAN. And its now clear when using the dataportal the code should run on the server. But when there is no client logged in, the server should keep these static variables in memory. It should remain state.

Is this going to happen, or do I need some programming for this?

 

ReadOnlyChild replied on Friday, September 28, 2007

on my previous proposal, the .GetNextNumber() method would take care of that persistence,

I would go for updating a table or updating a text file instead of leaving it to the app server memory, which I think could end up with more IFs and Catches in the long run...

Copyright (c) Marimer LLC