XUI Emulating Controllers is an infrastructure developed to enable the functions in the forms found on the fly to be used without opening forms or even on the server side. 
This infrastructure also supports multi-threading work.
We will examine an example of a material card insertion process with a multithreading controller
In the CFMultiThreadControllerHandler class, we initiate the operation on the server side by making a remote call from the client to the server.
 Click here to expand...
package com.EasyLPT_forCZRT.customization;
 
import com.lbs.transport.RemoteMethodResponse;
import com.lbs.xui.customization.JLbsXUIControlEvent;
 
public class CFMultiThreadControllerHandler {
 
    public CFMultiThreadControllerHandler() {
        // TODO Auto-generated constructor stub
    }
 
    public void onClickCallMultiThreadController(final JLbsXUIControlEvent event)
    {
        new Thread(new Runnable()
        {
           public void run()
           {
               try {
                    RemoteMethodResponse result = event.getClientContext().callRemoteMethod("CRSRV", "callMultiThreadController",
                            new Object [] {null});
                }
               catch (Exception e)
               {
                    e.printStackTrace();
                }
           }
        }).start();
    }
 
}

In the server-side CustomRemoteService class we first set the minimum, max and queucapacity values of LbsControllerUtil.configureTaskQueue (3, 10, 30, true). 
We create an instance of the LbsQueuedTask class and pass the ControllerSampleItemCard class, which we generate from j-guar, as a parameter.
 Click here to expand...
package com.EasyLPT_forCZRT.customization;
 
import java.util.GregorianCalendar;
 
import com.lbs.controllers.ILbsControllerTask;
import com.lbs.controllers.ILbsTaskParams;
import com.lbs.controllers.LbsControllerUtil;
import com.lbs.controllers.LbsQueuedTask;
import com.lbs.platform.interfaces.IServerContext;
import com.lbs.util.JLbsDateUtil;
 
public class CustomRemoteService {
 
    public void callMultiThreadController(IServerContext context)
    {
        ItemParams params = new ItemParams();
        try
        {
            LbsControllerUtil.configureTaskQueue(31030true);
            System.out.println("Multi task started :" + JLbsDateUtil.dateToString(GregorianCalendar.getInstance()));
            LbsQueuedTask queuedTask = new LbsQueuedTask(params, ControllerSampleItemCard.class)
            {
                @Override
                public void initialize(ILbsControllerTask currentTask, ILbsTaskParams params)
                {
                    if (currentTask instanceof ControllerSampleItemCard)
                    {
                        ControllerSampleItemCard itemTask = (ControllerSampleItemCard) currentTask;
                        itemTask.setParams((ItemParams) params);
                    }
                }
            };
             
            LbsControllerUtil.executeQueuedTask(context, queuedTask);
            LbsControllerUtil.waitForQueuedTasks(params, true);
 
        }
        catch (Exception e)
        {
            System.err.println("Error multitask : " + e.getMessage());
        }
        finally
        {
            System.out.println("Multi task  finished :" + JLbsDateUtil.dateToString(GregorianCalendar.getInstance()));
        }
         
    }
}

In the ItemParams class, the material card is prepared using the ItemModel class as many times as the number of "m_Counter" specified through the "next" method, and the multithread is executed in such a way as to work.

 Click here to expand...
package com.EasyLPT_forCZRT.customization;
 
import com.lbs.controllers.LbsTaskParamsBase;
 
 
public class ItemParams extends LbsTaskParamsBase
{
 
    private static final long serialVersionUID = 1L;
     
    protected int m_Counter = 0;
    protected static final ThreadLocal<ItemModel> ms_Item = new ThreadLocal<ItemModel>();
     
    @Override
    public boolean next()
    {
        synchronized (this)
        {
            if (!m_HasNext)
                return false;
             
            m_Counter++;
            if (m_Counter > 10)
                m_HasNext = false;
         
        }
        prepareItem();
        return m_HasNext;
    }
     
    private void prepareItem()
    {
        ItemModel item = new ItemModel();
        item.setDescription("Description-"+ m_Counter);
        item.setDescription2("2Description-"+ m_Counter);
        item.setAuxCode("AuxCode-"+ m_Counter);
        item.setAuthCode("AuthCode-"+ m_Counter);
        ms_Item.set(item);
    }
 
    public void reset()
    {
        m_Counter = 0;
    }
     
     
    public ItemModel getItem()
    {
        return ms_Item.get();
    }
 
    @Override
    public boolean isDisableGridQueries()
    {
        return true;
    }
 
     
    @Override
    public boolean canCache()
    {
        return true;
    }
     
     
    @Override
    public boolean isFastDocumentNumbers()
    {
        return false;
    }
     
}

You can access the source code of the project by clicking Link

 

https://docs.logo.com.tr/download/attachments/9732453/MultiThreadControllerDemo.rar?version=1&modificationDate=1490858911517&api=v2





Telif HakkıKullanım KoşullarıGizlilik
Copyright © 2018 Logo Yazılım