single instance

T

Twirlip of the Mists

You need to decide what you want to talk about.

If you want to consider "general civilian population" then go for
Windows and MacOS X - they don't know what a server is.

If you want to consider something else the say what it is.

What about "the vast majority of non-singletasking machines it's likely to
encounter, given it doesn't have an unusual specialized problem domain, and
that it can fairly easily be made to support"?

Then you recognize the ridiculousness of your position. Good.
 
A

Arne Vajhøj

What about "the vast majority of non-singletasking machines it's likely to
encounter, given it doesn't have an unusual specialized problem domain, and
that it can fairly easily be made to support"?

Sure.

But the fact that "the vast majority" is most relevant is
pretty trivial.
Then you recognize the ridiculousness of your position. Good.

The fact that a platform agnostic OS features do not exist
proves that I am right.

You can not get PID in a platform agnostic way.

Arne
 
J

Joshua Cranmer

Linux is used enough, especially on the server side, to cover, too, and
covering all Unixes isn't much harder than covering MacOS X, unless you
want a normal-looking native GUI, and with Java, using the native L&F
suffices for that.

As someone who has worked with cross-platform native projects, I will
truthfully say that covering all Unixes can be much harder than just OS
X, since OS X uses different graphics libraries, filesystem conventions,
desktop environment APIs, and even a different linker/loader than the
most common Unix-based varieties.
If anything genuinely and literally "has to work on all platforms" then
we're all fucked. :)

Low-level platform details--like filesystems--are surprisingly
different, even between platforms claiming to confirm to POSIX; that's
why there exists massive libraries to try to paper over these
differences. Even where there are standards, there are cases where some
implementations purposefully ignore them (the NFS atomic file creation
issue is a famous one).
 
T

Twirlip of the Mists

Sure.

But the fact that "the vast majority" is most relevant is
pretty trivial.

Then why are you harping on and on endlessly about it?
The fact that a platform agnostic OS features do not exist
proves that I am right.

You can not get PID in a platform agnostic way.

Using your very rigid definition of "platform agnostic", you can't do
anything in a platform agnostic way, not even add two and two. Using a
*useful* definition of "platform agnostic" -- say "runs on anything that
has an ANSI-compliant C compiler for it" or "runs on anything that has a
JLS-compliant JVM for it" -- it could conceivably be another story.
 
T

Twirlip of the Mists

As someone who has worked with cross-platform native projects, I will
truthfully say that covering all Unixes can be much harder than just OS
X, since OS X uses different graphics libraries, filesystem conventions,
desktop environment APIs, and even a different linker/loader than the
most common Unix-based varieties.


Low-level platform details--like filesystems--are surprisingly
different, even between platforms claiming to confirm to POSIX; that's
why there exists massive libraries to try to paper over these
differences. Even where there are standards, there are cases where some
implementations purposefully ignore them (the NFS atomic file creation
issue is a famous one).

Well, yes, if you try to make it work even on platforms that flagrantly
violate the relevant standards, then you're going to have problems. Making
a program that will work on systems that claim to support relevant
standards even if they in fact violate those standards is, in general, AI
complete; it's equivalent to making it work on arbitrary systems, since a
system that claims to follow, but violates, a standard is, when the opcodes
hit the CPU, no different from one that didn't even claim to follow any
standard at all. And no system, short of a human programmer's brain, is
known that's smart enough to port some code (itself, or something it's
acting as an installer for) to an arbitrary and novel system.

So the best you can typically do is program for a standard being respected,
and expect the code to be prone to fail on a system where the standard is
violated.
 
R

Roedy Green

The risk is, that in Windows anyway, where the system clock granularity
is 17ms it is possible to start two copies of a program with a batch

I have been studying Knute's code and Peter's commentary hoping to
come up with a canned package for ensuring single Instance.

Using system.nanotime aught to help avoid granularity trouble.

I am puzzled about "227.228.229.230" the IP used. Where did that
value come from? Can this be made to work with IPV6?
--
Roedy Green Canadian Mind Products http://mindprod.com
The first 90% of the code accounts for the first 90% of the development time.
The remaining 10% of the code accounts for the other 90% of the development
time.
~ Tom Cargill Ninety-ninety Law
 
R

Roedy Green

I am puzzled about "227.228.229.230" the IP used. Where did that
value come from? Can this be made to work with IPV6?

I discovered that 224.x.x.x - 239.x.x.x are reserved for IP multicast.
I could pick a random number in the range, or is it ok that everyone
uses the same IP or is it REQUIRED that everyone use the same IP

--
Roedy Green Canadian Mind Products http://mindprod.com
The first 90% of the code accounts for the first 90% of the development time.
The remaining 10% of the code accounts for the other 90% of the development
time.
~ Tom Cargill Ninety-ninety Law
 
R

Roedy Green

I have been studying Knute's code and Peter's commentary hoping to
come up with a canned package for ensuring single Instance.

If you had two machines on a LAN, would they prevent the other from
running a new instance? You don't want, that, just on the same
machine.

If you wanted that behaviour -- e.g. to enforce a single instance
licence across the LAN, what do you do have make the all one group?
--
Roedy Green Canadian Mind Products http://mindprod.com
The first 90% of the code accounts for the first 90% of the development time.
The remaining 10% of the code accounts for the other 90% of the development
time.
~ Tom Cargill Ninety-ninety Law
 
R

Roedy Green

I am puzzled about "227.228.229.230" the IP used. Where did that
value come from? Can this be made to work with IPV6?

This is beginning to come clear. This the name of the group. Everyone
sends and receives on the same socket on the same group.

Just as you have a problem assigning an unused socket, you have
assigning an unassigned group.

I don't see how this works between machines yet.

I think it should work like this:

You ask the OS , please assign me a free port. Here is a UUID. If
anyone asks for a port presenting the same UUID, please give him the
same one, no matter if he is calling from within the machine or
without. With such a scheme, you would not need reserved ports
(except for the port assigning port), and you could not have
collisions. Internally arrays of sockets could be dense. You can
then hard code in UUIDs into apps. Users don't need to worry about
collisions. Perhaps in IPV8.


--
Roedy Green Canadian Mind Products http://mindprod.com
The first 90% of the code accounts for the first 90% of the development time.
The remaining 10% of the code accounts for the other 90% of the development
time.
~ Tom Cargill Ninety-ninety Law
 
R

Roedy Green

You wouldn't need the OS to associate a UUID with a port; the UUID would
_be_ the port.

the UUID would be the port. The 16-bit port would just be an shorthand
abbreviation for it. You could even have a hybrid system. The
assigner just avoids well known ports or ports that have been
explicitly assigned.

don't port numbers appear in UDP packets and TCP/IP packets, though
the assignment of them may not be part of the protocol?

RFC 322 says that UCLA will maintain the list of reserved port
numbers.
--
Roedy Green Canadian Mind Products http://mindprod.com
The first 90% of the code accounts for the first 90% of the development time.
The remaining 10% of the code accounts for the other 90% of the development
time.
~ Tom Cargill Ninety-ninety Law
 
K

Knute Johnson

I have been studying Knute's code and Peter's commentary hoping to
come up with a canned package for ensuring single Instance.

Using system.nanotime aught to help avoid granularity trouble.

The problem with nanotime is that it is not guaranteed to use the same
starting point on different invocations of the VM. The granularity of
currentTimeMillis in Windows is large but not on Linux.
I am puzzled about "227.228.229.230" the IP used. Where did that
value come from? Can this be made to work with IPV6?

Arbitrary choice by me of a valid Multicast IP. I don't know any reason
why it would not work with IPV6 but I've never seen any discussion of it.
 
K

Knute Johnson

If you had two machines on a LAN, would they prevent the other from
running a new instance? You don't want, that, just on the same
machine.

If you wanted that behaviour -- e.g. to enforce a single instance
licence across the LAN, what do you do have make the all one group?

Same IP and port.
 
A

Arne Vajhøj

I have been studying Knute's code and Peter's commentary hoping to
come up with a canned package for ensuring single Instance.

Using system.nanotime aught to help avoid granularity trouble.

1) It uses a smaller unit, but does not guarantee a smaller
granularity.

2) It is only guaranteed to work within the same program as
the base is not fixed.

3) No matter how small a granularity, then it still just reduces
the risk of concurrency problems but does not eliminate the risk.

Arne
 
A

Arne Vajhøj

Since the problem is solveable using the existing mechanisms, I don't see a
compelling reason the above feature should be included in future versions
of IP.

Also, I'm no expert, but I'm not sure that any of the IP specifications
concern themselves with ports at all. That might be at the TCP and UDP
protocol levels, independent of the IP stuff.

Port numbers are indeed in the TCP and UDP header not in the IP header.

Arne
 
R

Roedy Green

We call that, in the programming community, a "hash code". It's not
unique, and therefore not useful as an actual port ID.


A hash is different. The assignment process might work with a HashMap
or like a HashMap. If hashes collide you assign different 16 bit
numbers. It is a dynamic process. You don't always get the same 16
bit port from the same UUID.

If you are sure the port is reserved for you, you just use the 16 bit
version. If not, you ask for a port reservation (good for perhaps one
second) given the UUID. Then you use the 16 bit port. When you close
it, the reservation disappears.
--
Roedy Green Canadian Mind Products http://mindprod.com
The first 90% of the code accounts for the first 90% of the development time.
The remaining 10% of the code accounts for the other 90% of the development
time.
~ Tom Cargill Ninety-ninety Law
 
R

Roedy Green

Same IP and port.

But how far does this ripple?
--
Roedy Green Canadian Mind Products http://mindprod.com
The first 90% of the code accounts for the first 90% of the development time.
The remaining 10% of the code accounts for the other 90% of the development
time.
~ Tom Cargill Ninety-ninety Law
 
M

markspace

But how far does this ripple?


As far as I know, it only works on your network segment. Only for
machines connected to the same physical router or gateway.

The multicast stuff is really more of a router protocol. A machine
broadcasts to one or more addresses, and the routers along the way take
care of passing the stream to interested client machines.

Also note that as far as I know, absolutely no routers implement this.
It's a dead protocol.
 
S

stledger

What is the best way to ensure only a single instance of a Java program is running. I have used indicator files, but they can get screwed up if the user kills the program without going through the standard shutdown. Ideally, net new instance would just join the one already running. This is pure GUI, so I am not worried about adding new command line parms. -- Roedy Green Canadian Mind Products http://mindprod.com Students who hire or con others to do their homework are as foolish as couch potatoes who hire others to goto the gym for them.

I worked on a project with a requirement to run only one instance of our software at a time. We had a configuration file that had initialization values for the software. If the file was missing, then the code had default values. The code was running on one computer. Our code worked like this:

try{
Socket sock = new Socket();
sock.bind(new InetSocketAddress(int value read from configuration file or default value));
} catch (java.net.BindException)
{ tell user they are trying to start more than one instance and shutdown this copy after user acknowledges }

It's simple and seemed to always work. We only had to worry about a user double clicking the application. We did not worry about a batch file trying to start more than one instance. Obviously, you could start one instance, delete the configuration file, then start the second instance. We judged this to be a very unlikely possibility given our users, so we didn't worry about it. The software backed up its data on shutdown, and at regular intervals, and kept several backup files going back over the last week, so it was possible to restore the data to a given time over the past week of operation. YMMV.

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top