working on it ...


Explore Public Snippets

Sort by

Found 3,098 snippets matching: interface

    public by micurs  748061  19  7  0

    JQuery typescript interface for $.ajax() callbacks

    To use JQuery $.ajax() you must define your callback functions with the following interfaces
    interface OnSuccessAjaxCallback {
      (data: any, textStatus?: string, jqXHR?: JQueryXHR): any;
    interface OnErrorAjaxCallback {
      (jqXHR?: JQueryXHR, textStatus?: string, errorThrow?: string) : any;

    public by lbottaro  406559  1  7  9

    Simple CORBA java server

    This code shows an example of simple corba server in java. A CORBA server needs a local ORB object. The server instantiates an ORB and registers its servant objects so that the ORB can find the server when it receives an invocation for it. the server is a process that instantiates one or more servant objects. Each servant implements the
    // The package containing our stubs.
    import HelloApp.*;
    // HelloServer will use the naming service.
    import org.omg.CosNaming.*;
    // The package containing special exceptions thrown by the name service.
    import org.omg.CosNaming.NamingContextPackage.*;
    // All CORBA applications need these classes.
    import org.omg.CORBA.*;
    public class HelloServer 
      public static void main(String args[])
           // Create and initialize the ORB
          ORB orb = ORB.init(args, null);
          // Create the servant and register it with the ORB
          HelloServant helloRef = new HelloServant();
          // Get the root naming context
        org.omg.CORBA.Object objRef = 
          NamingContext ncRef = NamingContextHelper.narrow(objRef);
          // Bind the object reference in naming
          NameComponent nc = new NameComponent("Hello", "");
          NameComponent path[] = {nc};
          ncRef.rebind(path, helloRef);
          // Wait for invocations from clients
          java.lang.Object sync = new java.lang.Object();
              } catch(Exception e) {
            System.err.println("ERROR: " + e);
    class HelloServant extends _HelloImplBase
      public String sayHello()
        return "\nHello world!!\n";

    public by lbottaro  311398  3  6  0

    Get MAC address of current interface in Python

    This python uses uuid.getnode to get current mac address as an integer. It formats the number in a standard mac address form (i.e. bytes splitted by :)
    import uuid
    print ':'.join(['{:02x}'.format((uuid.getnode() >> i) & 0xff) for i in range(0,8*6,8)][::-1])

    public by lbottaro  294402  1  6  3

    Simple RMI Java client

    This is a simple RMI client implementation. Here the client program obtains a stub for the registry on the server's host, then looks up the remote object's stub by name in the registry. Finally invokes the sayHello method on the remote object using the stub. Here the client invokes the method exposes by Hello remote interface. Note that if no
    package example.hello;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.registry.Registry;
    public class Client {
        private Client() {}
        public static void main(String[] args) {
    	String host = (args.length < 1) ? null : args[0];
    	try {
    	    Registry registry = LocateRegistry.getRegistry(host);
    	    Hello stub = (Hello) registry.lookup("Hello");
    	    String response = stub.sayHello();
    	    System.out.println("response: " + response);
    	} catch (Exception e) {
    	    System.err.println("Client exception: " + e.toString());

    public by lbottaro  281545  2  6  3

    Simple RMI Java server

    This code shows a basic RMI server example. A "server" is the class which has a main method that creates an instance of the remote object implementation, exports the remote object and then binds that instance to a name in a RMI registry. Here the server implements the remote interface Hello. The class that contains this main method could be the
    package example.hello;
    import java.rmi.registry.Registry;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.RemoteException;
    import java.rmi.server.UnicastRemoteObject;
    public class Server implements Hello {
        public Server() {}
        public String sayHello() {
    	return "Hello, world!";
        public static void main(String args[]) {
    	try {
    	    Server obj = new Server();
    	    Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);
    	    // Bind the remote object's stub in the registry
    	    Registry registry = LocateRegistry.getRegistry();
    	    registry.bind("Hello", stub);
    	    System.err.println("Server ready");
    	} catch (Exception e) {
    	    System.err.println("Server exception: " + e.toString());

    public by lbottaro  170268  0  6  0

    Simple RMI Java interface

    A simple RMI interface example. A remote interface extends the interface java.rmi.Remote and declares a set of remote methods. Each remote method must declare java.rmi.RemoteException (or a superclass of RemoteException) in its throws clause, in addition to any application-specific exceptions. This interface declares just one method, sayHello, w
    package example.hello;
    import java.rmi.Remote;
    import java.rmi.RemoteException;
    public interface Hello extends Remote {
        String sayHello() throws RemoteException;

    public by lbottaro  2033  1  6  1

    Java interface - IPerson

    This is the interface implemented by EJB, as shown in previous snippet.
    package com.test.example.interfaces;
    import java.util.Collection;
    import java.util.List;
    import com.test.example.person.Person;
    public interface IPerson {
    	public Person getPerson(int id);
    	public List<Person> getPersonList();
    	public Person addPerson(Person p);
    	public Person updatePerson(Person p);
    	public void deletePerson(int id);
    	public Collection<Person> searchPersons(String completeName);

    public by lbottaro  3618  3  6  3

    How to invoke the EJB remote interface - Java client application

    The codes shows how to remotely invoke the methods exposed by EJB remote interface. The client app will invoke the remote methods using a JNDI lookup. The appName and beanName refer to the remote application and ejb names to be referenced by the client app. Notice the usage of InitialContext, setting variables INITIAL_CONTEXT_FACTORY and PROVIDE
    package com.test.ejbclient;
    import java.util.List;
    import java.util.Properties;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import com.test.example.interfaces.IPerson;
    import com.test.example.person.*;
    public class Ejbclient {
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		IPerson person = doLookup();
    		Person p = person.getPerson(4);
    		List<Person> pList = person.getPersonList();
    		for (Person person2 : pList) {
    	private static IPerson doLookup() {
    		IPerson bean = null;
    		try {
    			bean = lookupRemoteStatelessPersonEJB();
    		} catch (NamingException e) {
    			// TODO Auto-generated catch block
    		return bean;
    	private static String getLookupName() {
    		//The app name
            final String appName = "PersonWebAppEJB_Final";
            // The EJB name which by default is the simple class name of the bean implementation class
            final String beanName = "PersonEJB";
            // the remote view fully qualified class name
            final String viewClassName = IPerson.class.getName();
            // let's do the lookup
            String url = appName + "/" +beanName + "!" + viewClassName;
            System.out.println("URL: " + url);
    		return url;
    	private static IPerson lookupRemoteStatelessPersonEJB() throws NamingException {
    		Properties env = new Properties(); 
    		env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
    		env.put(Context.PROVIDER_URL, "remote://");
    		String userName = "user";
    		String password = "password";
    		env.put(Context.SECURITY_PRINCIPAL, userName);
    		env.put(Context.SECURITY_CREDENTIALS, password);
    		env.put("jboss.naming.client.ejb.context", true);
    		InitialContext context = new InitialContext(env); 
            // let's do the lookup
            String url = getLookupName();
            return (IPerson) context.lookup(url);

    public by lbottaro  2600  1  6  4

    Simple java Callable interface implementation

    This object implements the interface Callable because you expect your threads to return a computed result. In this case a simple sum of long type is executed into call() method.
    import java.util.concurrent.Callable;
    public class MyCallableObject implements Callable<Long> {
      public Long call() throws Exception {
        long sum = 0;
        for (long i = 0; i <= 100; i++) {
          sum += i;      
        return sum;

    public by lbottaro  3818  1  6  1

    Java Qualifier - Implementing Observer Design Pattern using interface

    This code shows a simple java interface. The Qualifier annotation allows to specify this interface as used by other class. This will allow to implement the Observer / Listener Design pattern.
    package com.test.example.interfaces;
    import java.lang.annotation.ElementType;
    import java.lang.annotation.Retention;
    import java.lang.annotation.RetentionPolicy;
    import java.lang.annotation.Target;
    import javax.inject.Qualifier;
    @Target({ElementType.FIELD, ElementType.METHOD, ElementType.TYPE, ElementType.PARAMETER})
    public @interface IPersonMethodInvoke {
    • Public Snippets
    • Channels Snippets