Table/container confusion

Here is my table


public class GeneratedReportTable extends Table
{
    public GeneratedReportTable( ICEPush icePush,
                                 ScheduledThreadPoolExecutor scheduledThreadPoolExecutor,
                                 GeneratedReportManager generatedReportManager )
    {
        setSizeFull();
        
        GeneratedReportDataSource generatedReportDataSource =
            new GeneratedReportDataSource( icePush, this, scheduledThreadPoolExecutor, generatedReportManager );

        setContainerDataSource( generatedReportDataSource );
    }
}

Here is my container


public class GeneratedReportDataSource extends BeanItemContainer<GeneratedReport> implements Runnable
{
    private static final Logger LOGGER = Logger.getLogger( GeneratedReportDataSource.class );

    private GeneratedReportManager generatedReportManager;
    private ScheduledThreadPoolExecutor scheduledThreadPoolExecutor;
    private ICEPush icePush;
    private GeneratedReportTable generatedReportTable;

    private int numnberOfRowsToSkip = 1;

    public GeneratedReportDataSource( ICEPush icePush,
                                      GeneratedReportTable generatedReportTable,
                                      ScheduledThreadPoolExecutor scheduledThreadPoolExecutor,
                                      GeneratedReportManager generatedReportManager )
        throws IllegalArgumentException
    {
        super( generatedReportManager.getGeneratedReportList( null ).getGeneratedReportList() );

        this.generatedReportTable = generatedReportTable;
        this.icePush = icePush;
        this.generatedReportManager = generatedReportManager;
        this.scheduledThreadPoolExecutor = scheduledThreadPoolExecutor;

        scheduledThreadPoolExecutor.scheduleAtFixedRate( this, 20, 20, TimeUnit.SECONDS );
    }

    @Override
    protected void finalize() throws Throwable
    {
        super.finalize();

        if ( scheduledThreadPoolExecutor != null )
        {
            scheduledThreadPoolExecutor.remove( this );
        }
    }

    @Override
    public void run()
    {
        List<GeneratedReport> generatedReportList = generatedReportManager.getGeneratedReportList( null ).getGeneratedReportList();
LOGGER.warn( "size == " + size( ) );

        /*ArrayList<GeneratedReport> deleteList = new ArrayList<GeneratedReport>( );
        for ( GeneratedReport generatedReport : getItemIds() )
        {
            if ( !generatedReportList.contains( generatedReport ) )
            {
                deleteList.add( generatedReport );
            }
        }

        for ( GeneratedReport generatedReport : deleteList )
        {
            removeItem( generatedReport );
        }*/

        removeAllItems();

        int loopCount = 0;
        for ( GeneratedReport generatedReport : generatedReportList )
        {

            if ( getItem( generatedReport ) == null )
            {
                if ( loopCount++ >= numnberOfRowsToSkip )
                {
                    break;
                }
                addItem( generatedReport );
            }
        }
        generatedReportTable.requestRepaint();
LOGGER.warn( "size == " + size( ) );
        icePush.push();

        numnberOfRowsToSkip++;
    }
}

Here is my Serializable object


public class GeneratedReport implements Serializable
{
    private String reportName;
    private GeneratedReportTypeEnum generatedReportTypeEnum;
    private TMCLocationTypeEnum tmcLocationTypeEnum;
    private String baseLineProductKey;
    private String compareProductKey;
    private Date creationDate;
    private int creationTime;

    private boolean useRoadClosures;
    private boolean includeBSARecords;
    
   /* LAST_X_FILES=1
TIME_RANGE_CYCLE_TIME=150*/

    private GeneratedReport()
    {
    }

    public GeneratedReport( String reportName,
                            GeneratedReportTypeEnum generatedReportTypeEnum,
                            TMCLocationTypeEnum tmcLocationTypeEnum,
                            String baseLineProductKey,
                            String compareProductKey,
                            Date creationDate,
                            int creationTime,
                            boolean useRoadClosures,
                            boolean includeBSARecords )
    {
        this.reportName = reportName;
        this.tmcLocationTypeEnum = tmcLocationTypeEnum;
        this.generatedReportTypeEnum = generatedReportTypeEnum;
        this.baseLineProductKey = baseLineProductKey;
        this.compareProductKey = compareProductKey;
        this.creationDate = creationDate;
        this.creationTime = creationTime;
        this.useRoadClosures = useRoadClosures;
        this.includeBSARecords = includeBSARecords;
    }

    public String getReportName()
    {
        return reportName;
    }

    public void setReportName( String reportName )
    {
        this.reportName = reportName;
    }

    public GeneratedReportTypeEnum getGeneratedReportTypeEnum()
    {
        return generatedReportTypeEnum;
    }

    public void setGeneratedReportTypeEnum( GeneratedReportTypeEnum generatedReportTypeEnum )
    {
        this.generatedReportTypeEnum = generatedReportTypeEnum;
    }

    public TMCLocationTypeEnum getTmcLocationTypeEnum()
    {
        return tmcLocationTypeEnum;
    }

    public void setTmcLocationTypeEnum( TMCLocationTypeEnum tmcLocationTypeEnum )
    {
        this.tmcLocationTypeEnum = tmcLocationTypeEnum;
    }

    public String getBaseLineProductKey()
    {
        return baseLineProductKey;
    }

    public void setBaseLineProductKey( String baseLineProductKey )
    {
        this.baseLineProductKey = baseLineProductKey;
    }

    public String getCompareProductKey()
    {
        return compareProductKey;
    }

    public void setCompareProductKey( String compareProductKey )
    {
        this.compareProductKey = compareProductKey;
    }

    public Date getCreationDate()
    {
        return creationDate;
    }

    public void setCreationDate( Date creationDate )
    {
        this.creationDate = creationDate;
    }

    public int getCreationTime()
    {
        return creationTime;
    }

    public void setCreationTime( int creationTime )
    {
        this.creationTime = creationTime;
    }

    public boolean isUseRoadClosures()
    {
        return useRoadClosures;
    }

    public void setUseRoadClosures( boolean useRoadClosures )
    {
        this.useRoadClosures = useRoadClosures;
    }

    public boolean isIncludeBSARecords()
    {
        return includeBSARecords;
    }

    public void setIncludeBSARecords( boolean includeBSARecords )
    {
        this.includeBSARecords = includeBSARecords;
    }

    @Override
    public boolean equals( Object compareObject )
    {
        if ( this == compareObject )
        {
            return true;
        }
        if ( compareObject == null || getClass() != compareObject.getClass() )
        {
            return false;
        }

        GeneratedReport that = (GeneratedReport) compareObject;

        if ( reportName != null ? !reportName.equals( that.reportName ) : that.reportName != null )
        {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode()
    {
        return reportName != null ? reportName.hashCode() : 0;
    }
}

My issue is that whenever I update the container in a separate thread the changes dont get to the table itself.
I thought I read that they should?
Also, I have tried ICEPush but I realize I may not be doing that correctly?

Hi,

Quick notes:

  • You need to synchronize on each application instance that is using the container instance, before updating the content ( synchronized(application){…} )

  • If you update the Beans themselves (pojos) directly, w/o going trough the Container API, the Container will not notice the changes.

  • ICEPush needs to be added to your layout to work, and you must use you must use org.vaadin.artur.icepush.ICEPushServlet instead of com.vaadin.terminal.gwt.server.ApplicationServlet.

Not sure if this solves your problems, but those are the most common gotchas…

Best Regards,
Marc

How would you use a container across many application instances?
Is this possible?
I thought it was necessary for each instance to have its own container?

Well… it’s possible, but not recommended - ymmv. Containers are usually not made with this in mind, so if you don’t craft your own Container very carefully, it’s very easy to end up leaking memory.

Best Regards,
Marc

Thanks for your help mark your previous answer helped me along