Subject Service name in GDS
Author Ruslan Cheremin
Hello, All!

Currently I'm using JBird to connect Firebird server API. The exactly task I working
for is checking, is server is running. For such a thing I was trying just to try to
connect to "anonymous" Firebird service and see, can it accept connections. Code like
this (it was adopted from C):
final AbstractGDS gds = ...;

final String serviceName = "localhost:3050/anonymous";

final ServiceParameterBuffer spb = gds.createServiceParameterBuffer();

//don't sure do we need it -- all works even if missed
//new byte[] { 120, 10, 0, 0 });

final IscSvcHandle handle = gds.createIscSvcHandle();
try {
gds.iscServiceAttach( serviceName, handle, spb );
gds.iscServiceDetach( handle );
return true;
} catch ( GDSException e ) {
return false;

But I've got an error executing this code. Digging source of
AbstractJavaGDSImpl.iscServiceAttach( service, handle, spb ) I've found, that, although
there is explicit parameter service, inside method there is explicit check for it to
be "<host>:<port>/service_mgr" -- serviceName can be "service_mgr" only:
String serviceMgrStr = "service_mgr";
int mgrIndex = service.indexOf(serviceMgrStr);
if (mgrIndex == -1 || mgrIndex + serviceMgrStr.length() != service.length())
throw new GDSException(ISCConstants.isc_arg_gds, ISCConstants.isc_svcnotdef, service);

I suppose, it's some kind of self-check, it seems, inside JBird only "service_mgr" service
used. But it is not explicit, and not logical for me. If I can suggest, my suggestion will
1. gds.iscServiceAttach( serviceName, handle, spb ) does not check for serviceName at all.
Suppose it to be universal.
2. create method gds.iscServiceAttach( host, port, handle, spb ), which is mapped to
gds.iscServiceAttach( String.format("%s:%d/%s", host, port, "service_mgr"), handle, spb )
-- and this method should be used inside JBird.
3. I also noticed, that "service_mgr" string constant used at least twice in JBird sources,
and both time assigned explicitly in method code -- like in example above. I suppose it
will be better to extract it in some constant field like
public static final String DEFAULT_SERVICE_NAME = "service_mgr";
It makes code slightly less misterios :)