简体   繁体   中英

How can I get the composite field column in Java mission control's event browser?

I am able to see the primitive data type used in java class in the event browser's table of Java Mission Control. But it is not showing the composite data types.

My code is:

package com.foo.bar;

public class AB {

    @Name("com.foo.bar.Author")    
    @Label("Author Event")
    public static class Author extends Event {
    
      String authorName;
      int age;
      String place;

      Author(String name, int age, String place)
      {
        this.authorName = name;
        this.age = age;
        this.place = place;
      }

}


@Name("com.foo.bar.Book")    
@Label("Book Event")
public static class Book extends Event
{
  String name;
  int price;
  // author details
  Author auther;
  Book(String n, int p, Author auther)
  {
    this.name = n;
    this.price = p;
    this.auther = auther;
  }
}

  public static void main(String[] args) throws InterruptedException {
    Author author = new Author("John", 42, "USA");
    Book b = new Book("Java for Begginer", 800, author);
    b.begin();
    author.begin();
    author.commit();
    b.commit();

  }
}

And I am getting something like this in JMC:

How can I get the Author details in Book event? Is there a way in JMC to get the composite data in event browser's column?

Thanks

You don't. You relate the events to each other. Ie the author event and the book event should probably both have an authorId in them.

See, for example, how the gc id is used to relate garbage collection related events to each other.

Jave events can't store composite data in fields, but you can link events together as suggested by Hirt.

@MetadataDefinition
@Name("com.example.BookAuthor")
@Label("Book Author")
@Relational
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
public @interface BookAuthor {
}

@Name("com.example.Author")    
@Label("Author")
public class Author extends Event {
  @Label("Author");
  String authorName;
  @Label("Age");
  int age;
  @Label("Place");
  String place;
  @Label("Author ID");
  @BookAuthor
  long id;
}

@Name("com.example.Book")    
@Label("Book")
public class Book extends Event {
  @Label("Name")
  String name;
  @Label("Price")
  int price;
  @Label("Author ID")
  @BookAuthor
  long authorId;
}

JDK Mission Control GUI, as of today, won't group them together, but that is how a relation is expressed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM