piątek, 14 czerwca 2013

RMI headache - (too) many network interfaces



Assuming we have more then one network interface on our machine and assuming they are no routeable each other you can be faced a wierd behavior of RMI RemoteObject.

If you use TCP protocol as a transport creating an object of UnicastServerRef underneeth there is LifeRef object created, which in turn calls TCPEndpoint.getLocalEndpoint() method.

getLocalEndpoint() implementation do the following:
  • creates TCPEndpoint object with null value passed as hostname
  • resamples local host
return AccessController.doPrivileged(new GetPropertyAction("java.rmi.server.hostname"));

So make sure it points to the proper one ;).

wtorek, 21 maja 2013

VBScript for begginers


Some initial facts


  • Concatenation operator: &
  • No semicolon required at the end of line



Most basic constructs



  • Allocation: Dim aRoot as Root
  • Assingment:  Set aParam = CurrentTSTest
  • TypeOf
    • If TypeOf p Is IParameterValue Then 
          TDOutput.Print("Value: " & p.Value)
      End If 
  • TypeName(o) - displays type of  the object passed.

 

Loop statements


  •  For Each param In lst
            With param
              TDOutput.Print("Name: " & .Name & ", Value: " & .DefaultValue)
            End With
    Next
 
  • Dim i%
        For i = 1 To lst.Count
            Set instance = lst.Item(i)
            Debug.Print "Instance name: " & instance.name & " id: " & instance.ID
    Next i
     



Useful links:

środa, 5 września 2012

Ubuntu 12.04 - Installing both maven3 and maven2 as alternatives

Maven and /etc/alternatives


Ubuntu 12.04 comes with maven 3.0.4 as a default - that's great, but not for those who still needs maven 2.x. Unfortunately maven2 package can be installed can be installed only as the maven3 replacement - for those needed both, that sounds rather poor solution. Luckly there is /etc/alternatives mechanism that is perfect in such a case. It basically allows us having both with relativly easy way. But in that case alternatives does not work out of the box. The only way to handle this is installing maven2 binaries manually and register it as an alternative for mvn command.

How to do this - step by step solution: 

  1. Lets start with installing maven3 (3.0.4-2)
    $ sudo apt-get install maven
  2. Once done we look at recently installed mvn using update-alternatives command.
    $ update-alternatives --list mvn
     /usr/share/maven/bin/mvn
    $ update-alternatives --display mvn
    mvn - auto mode
      link currently points to /usr/share/maven/bin/mvn
    /usr/share/maven/bin/mvn - priority 150
      slave mvn.1.gz: /usr/share/maven/man/mvn.1.gz
      slave mvnDebug: /usr/share/maven/bin/mvnDebug
      slave mvnDebug.1.gz: /usr/share/maven/man/mvnDebug.1.gz
    Current 'best' version is '/usr/share/maven/bin/mvn'.
    Optionally fix the mvnDebug link into /usr/bin/mvnDebug
    ln -s /etc/alternatives/mvnDebug /usr/bin/mvnDebug
    
  3. Download maven 2 and extract it into /usr/share/maven2 folder.
  4. # cd /usr/share && wget http://archive.apache.org/dist/maven/binaries/apache-maven-2.2.1-bin.tar.gz
    
    # tar xzvf apache-maven-2.2.1-bin.tar.gz && mv apache-maven-2.2.1 maven2 && rm apache-maven-2.2.1-bin.tar.gz
    
  5. Add alternatives
    # update-alternatives --install /usr/bin/mvn mvn /usr/share/maven2/bin/mvn 200 --slave /usr/bin/mvnDebug mvnDebug /usr/share/maven2/bin/mvnDebug
    
    Priority 200 as a greater then 150 makes maven2 it the default (auto).
  6. Now you can display current alternatives for mvn command
    $ update-alternatives --display mvn
    mvn - auto mode
      link currently points to /usr/share/maven2/bin/mvn
    /usr/share/maven/bin/mvn - priority 150
      slave mvn.1.gz: /usr/share/maven/man/mvn.1.gz
      slave mvnDebug: /usr/share/maven/bin/mvnDebug
      slave mvnDebug.1.gz: /usr/share/maven/man/mvnDebug.1.gz
    /usr/share/maven2/bin/mvn - priority 200
      slave mvnDebug: /usr/share/maven2/bin/mvnDebug
    Current 'best' version is '/usr/share/maven2/bin/mvn'.
    
  7. In order to switch between maven versions use
     # update-alternatives --config mvn
    
  8. The same way you can add 3.2 release:
    # update-alternatives --install /usr/bin/mvn mvn /usr/share/maven32/bin/mvn 320 --slave /usr/bin/mvnDebug mvnDebug /usr/share/maven32/bin/mvnDebug
    

wtorek, 22 marca 2011

Breadcrumbs composite with SWT (Eclipse Forms)

Breadcrumbs panel is very popular navigation widget. Especially useful when comes to navigation in big hierarchical models where one need a way to quickly move to the parent elements.


At the picture you can see breadcrumbs in action.

Implementation details


Two providers needs to be delivered to BreadcrumbsPanel instance: IBreadcrumbsItemProvider and IBreadcrumbsLinkActionProvider.

public interface IBreadcrumbsItemProvider{
  public List<IBreadcrumbsItem> getBreadcrumbs();
 }

 public interface IBreadcrumbsLinkActionProvider{
  public void run(IBreadcrumbsItem item);
 }

 public interface IBreadcrumbsItem {
  public abstract Object getObject();
  public abstract String getLabel();
 }

Instances of both providers needs to be delivered to BreadcrumbsPanel constructor.

public BreadcrumbsPanel(
             FormToolkit toolkit, // only when composite is used with Eclipse Forms
             Composite parent, 
             IBreadcrumbsItemProvider itemProvider, 
             final IBreadcrumbsLinkActionProvider actionProvider) {
  super(parent, SWT.NONE);
  this.toolkit = toolkit;
  this.itemProvider = itemProvider;
  this.actionProvider = actionProvider;
  
  this.setLayout(new RowLayout());
  updateLinks();
 }

UpdateLinks method is particularly important piece of code here. It is responsible for generating actual list of hyperlinks. This method make use of both providers. For each element returned by item provider creates a hyperlink control which on click will performed an action delivered with action provider.

private void updateLinks() {
  
  for (Control c :this.getChildren()){
   if (c instanceof Hyperlink || c instanceof Label){
    c.dispose();
   }
  }
  
  links = new ArrayList<Hyperlink>();
  
  final List<IBreadcrumbsItem> items = itemProvider.getBreadcrumbs();
  
  for (int i = 0;i < items.size(); i++) { 
   String label = items.get(i).getLabel();
   if (1+i < items.size()){
    Hyperlink link = toolkit.createHyperlink(this, label, SWT.None);
    link.setHref(items.get(i));
    
    toolkit.createLabel(this, "/");
    
    link.addHyperlinkListener(new HyperlinkAdapter(){
     @Override
     public void linkActivated(HyperlinkEvent e) {
      if (e.getHref() instanceof IBreadcrumbsItem){
       actionProvider.run((IBreadcrumbsItem)e.getHref());
      }
     }
    });
    links.add(link);
   } else {
    toolkit.createLabel(this, label);
   }
  }
 }

Note that in case of pure SWT you may use raw Link and Label controls.

piątek, 18 lutego 2011

Ubuntu: apt-get - how to install already installed package

Let's imagine a case where one has been removed by chance some files comes with one of deb packages installed with apt-get utility.

For sake of this example lets remove /usr/lib/php5/20060613/pdo_mysql.so file.

Now after Apache restart the following entry will appear in /var/log/apache2/error.log
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613/pdo_mysql.so' 
- /usr/lib/php5/20060613/pdo_mysql.so: cannot open shared object file: 
No such file or directory in Unknown on line 0

In this particular case is quite easy to guess which package pdo_mysql.so file comes with. But in general dpkg --search can help.

$ dpkg --search /usr/lib/php5/20060613/pdo_mysql.so
php5-mysql: /usr/lib/php5/20060613/pdo_mysql.so

Now we know for sure which packed needs to be installed again. To ask apt-get to install package which already is installed --reinstall option needs to be used.

sudo apt-get --reinstall install php5-mysql

Now pdo_mysql.so should be again on its place.

czwartek, 10 lutego 2011

Linux - "find" command by examples

  • Remove all subversion metadata (all directories with .svn name)
    find . -type d -name ".svn" | xargs rm -rf
    
  • Remove all file begining with two digits number followed by underscore character
    find . -name "[0-9][0-9]_*" | xargs rm -rf
    
  • Find all file which where modified within last 24 hours
    find . -mtime 0
    

piątek, 14 stycznia 2011

Eclipse PDT most useful shortcuts

Today I would like to share and keep for the future couple of tricks I found out today after years of working with Eclipse (shame - I know ;).

Incremental search (Ctrl+J)


First of all if you miss "/" command of your favourite vi editor the Ctrl+J is what you need. Once you type pharse you looking for (look at status bar - red color surprisingly means "sorry no match"). But if you are lucky "Up/Down" key buttons allow you navigate back and forth among all found matches (b/n for vi masters ;>).

Open Type (Ctrl+Shift+T)


Immortal Ctrl+Shift+T works as well allows you open any Type available in workspace.

Quick Outline (Ctrl+O)


Ctrl+O invoke nice yellow frame with outline view. Local search ability and "Up/Down" keys allow you handy navigation.