How to set TCP Keep-Alive for JNDI Connection ?

View: New views
4 Messages — Rating Filter:   Alert me  

How to set TCP Keep-Alive for JNDI Connection ?

by Vineet Vyas :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Hi All,

 

I need to set TCP Keep-Alive flag true for JNDI Client Connection with the Directory Server.

Can anyone provide me any suggestion of how can it be done ?

 

I am using com.sun.jndi.ldap.LdapCtxFactory and Sun JNDI Provider.

 

Thanks in advance for any help in this regard.

 

Thanks

Vineet

DISCLAIMER ========== This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails.

=========================================================================== To unsubscribe, send email to listserv@... and include in the body of the message "signoff JNDI-INTEREST". For general help, send email to listserv@... and include in the body of the message "help".

Re: How to set TCP Keep-Alive for JNDI Connection ?

by Chun Tat David Chu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Vineet,

I have never set TCP keep-alive on JNDI client, but I know for sure that's something you can set on the directory server side.

- dc

On Fri, May 16, 2008 at 8:10 AM, Vineet Vyas <vineet_vyas@...> wrote:

Hi All,

 

I need to set TCP Keep-Alive flag true for JNDI Client Connection with the Directory Server.

Can anyone provide me any suggestion of how can it be done ?

 

I am using com.sun.jndi.ldap.LdapCtxFactory and Sun JNDI Provider.

 

Thanks in advance for any help in this regard.

 

Thanks

Vineet

DISCLAIMER ========== This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails.

=========================================================================== To unsubscribe, send email to listserv@... and include in the body of the message "signoff JNDI-INTEREST". For general help, send email to listserv@... and include in the body of the message "help".

=========================================================================== To unsubscribe, send email to listserv@... and include in the body of the message "signoff JNDI-INTEREST". For general help, send email to listserv@... and include in the body of the message "help".

Re: How to set TCP Keep-Alive for JNDI Connection ?

by vincent.ryan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You could set the Socket.setKeepAlive metod to set the TCP flag:

http://java.sun.com/javase/6/docs/api/java/net/Socket.html#setKeepAlive(boolean)

However in order to gain acess to the Socket you would have to supply a
custom SocketFactory to JNDI. The factory could simply be a wrapper around
the default socket factory that explicitly sets the keep-alive flag.

See the Custom Sockets section in the JNDI Tutorial for more details:

http://java.sun.com/products/jndi/tutorial/ldap/security/ssl.html



Chun Tat David Chu wrote:

> Hi Vineet,
>
> I have never set TCP keep-alive on JNDI client, but I know for sure
> that's something you can set on the directory server side.
>
> - dc
>
> On Fri, May 16, 2008 at 8:10 AM, Vineet Vyas
> <vineet_vyas@... <mailto:vineet_vyas@...>> wrote:
>
>     Hi All,
>
>      
>
>     I need to set TCP Keep-Alive flag true for JNDI Client Connection
>     with the Directory Server.
>
>     Can anyone provide me any suggestion of how can it be done ?
>
>      
>
>     I am using *com.sun.jndi.ldap.LdapCtxFactory* and Sun JNDI Provider.
>
>      
>
>     Thanks in advance for any help in this regard.
>
>      
>
>     Thanks
>
>     Vineet
>
>     DISCLAIMER ========== This e-mail may contain privileged and
>     confidential information which is the property of Persistent Systems
>     Ltd. It is intended only for the use of the individual or entity to
>     which it is addressed. If you are not the intended recipient, you
>     are not authorized to read, retain, copy, print, distribute or use
>     this message. If you have received this communication in error,
>     please notify the sender and delete all copies of this message.
>     Persistent Systems Ltd. does not accept any liability for virus
>     infected mails.
>
>     ===========================================================================
>     To unsubscribe, send email to listserv@...
>     <mailto:listserv@...> and include in the body of the
>     message "signoff JNDI-INTEREST". For general help, send email to
>     listserv@... <mailto:listserv@...> and include in
>     the body of the message "help".
>
>
> ===========================================================================
> To unsubscribe, send email to listserv@... and include in the
> body of the message "signoff JNDI-INTEREST". For general help, send
> email to listserv@... and include in the body of the message
> "help".

===========================================================================
To unsubscribe, send email to listserv@... and include in the body
of the message "signoff JNDI-INTEREST".  For general help, send email to
listserv@... and include in the body of the message "help".

Parent Message unknown Re: How to set TCP Keep-Alive for JNDI Connection ?

by vincent.ryan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

JNDI provides an abstract naming interface which is explicitly designed to hide
much of the details of underlying connections and protocol elements.

I've attached a trival custom socket factory. You'll need to call setKeepAlive
in each of its createSocket methods before returning the Socket object. Then
just add the following line to your JNDI application to activate the factory:

    env.put("java.naming.ldap.factory.socket", "MyCustomSocketFactory");




Vineet Vyas wrote:

> Hi Vincent,
>
> Thanks for your reply.
>
>  I do understand that through custom sockets I might be able to achieve TCP
> Keep-Alive.
> But I wonder is there any simpler approach to this. I thought there might be
> a very obvious requirement for any JNDI Client.
>
>  I haven't tried the Custom Socket myself but if u have any idea what should
> one keep in my mind while writing any Custom Socket. I meant with respect to
> connection pooling and other features...
>
> Thanks
> Vineet
>
> -----Original Message-----
> From: A mailing list for discussing Java Naming and Directory Interface
> (JNDI) [mailto:JNDI-INTEREST@...] On Behalf Of Vincent Ryan
> Sent: Friday, May 16, 2008 7:33 PM
> To: JNDI-INTEREST@...
> Subject: Re: How to set TCP Keep-Alive for JNDI Connection ?
>
> You could set the Socket.setKeepAlive metod to set the TCP flag:
>
> http://java.sun.com/javase/6/docs/api/java/net/Socket.html#setKeepAlive(bool
> ean)
>
> However in order to gain acess to the Socket you would have to supply a
> custom SocketFactory to JNDI. The factory could simply be a wrapper around
> the default socket factory that explicitly sets the keep-alive flag.
>
> See the Custom Sockets section in the JNDI Tutorial for more details:
>
> http://java.sun.com/products/jndi/tutorial/ldap/security/ssl.html
>
>
>
> Chun Tat David Chu wrote:
>> Hi Vineet,
>>
>> I have never set TCP keep-alive on JNDI client, but I know for sure
>> that's something you can set on the directory server side.
>>
>> - dc
>>
>> On Fri, May 16, 2008 at 8:10 AM, Vineet Vyas
>> <vineet_vyas@... <mailto:vineet_vyas@...>>
> wrote:
>>     Hi All,
>>
>>      
>>
>>     I need to set TCP Keep-Alive flag true for JNDI Client Connection
>>     with the Directory Server.
>>
>>     Can anyone provide me any suggestion of how can it be done ?
>>
>>      
>>
>>     I am using *com.sun.jndi.ldap.LdapCtxFactory* and Sun JNDI Provider.
>>
>>      
>>
>>     Thanks in advance for any help in this regard.
>>
>>      
>>
>>     Thanks
>>
>>     Vineet
>>
>>     DISCLAIMER ========== This e-mail may contain privileged and
>>     confidential information which is the property of Persistent Systems
>>     Ltd. It is intended only for the use of the individual or entity to
>>     which it is addressed. If you are not the intended recipient, you
>>     are not authorized to read, retain, copy, print, distribute or use
>>     this message. If you have received this communication in error,
>>     please notify the sender and delete all copies of this message.
>>     Persistent Systems Ltd. does not accept any liability for virus
>>     infected mails.
>>
>>
> ===========================================================================
>>     To unsubscribe, send email to listserv@...
>>     <mailto:listserv@...> and include in the body of the
>>     message "signoff JNDI-INTEREST". For general help, send email to
>>     listserv@... <mailto:listserv@...> and include in
>>     the body of the message "help".
>>
>>
>>
> ===========================================================================
>> To unsubscribe, send email to listserv@... and include in the
>> body of the message "signoff JNDI-INTEREST". For general help, send
>> email to listserv@... and include in the body of the message
>> "help".
>
> ===========================================================================
> To unsubscribe, send email to listserv@... and include in the body
> of the message "signoff JNDI-INTEREST".  For general help, send email to
> listserv@... and include in the body of the message "help".
>
>
> DISCLAIMER
> ==========
> This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails.
===========================================================================
To unsubscribe, send email to listserv@... and include in the body
of the message "signoff JNDI-INTEREST".  For general help, send email to
listserv@... and include in the body of the message "help".


import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import javax.net.SocketFactory;

/*
 * A custom socket factory used to override the default socket factory.
 * See the ConnectionTests/UseCustomSocketFactory test.
 */

public class MyCustomSocketFactory extends SocketFactory {

    public MyCustomSocketFactory() {

        System.out.println("[creating a custom socket factory]");
    }

    public static SocketFactory getDefault() {

        System.out.println("[acquiring the default socket factory]");
        return new MyCustomSocketFactory();
    }

    public Socket createSocket(String host, int port)
        throws IOException, UnknownHostException {

        System.out.println("[creating a custom socket (method 1)]");
        return new Socket(host, port);
    }

    public Socket createSocket(String host, int port, InetAddress localHost,
        int localPort) throws IOException, UnknownHostException {

        System.out.println("[creating a custom socket (method 2)]");
        return new Socket(host, port, localHost, localPort);
    }

    public Socket createSocket(InetAddress host, int port) throws IOException {

        System.out.println("[creating a custom socket (method 3)]");
        return new Socket(host, port);
    }

    public Socket createSocket(InetAddress address, int port,
        InetAddress localAddress, int localPort) throws IOException {

        System.out.println("[creating a custom socket (method 4)]");
        return new Socket(address, port, localAddress, localPort);
    }
}


===========================================================================
To unsubscribe, send email to listserv@... and include in the body
of the message "signoff JNDI-INTEREST".  For general help, send email to
listserv@... and include in the body of the message "help".